因此,AlertDialog的Negative和Positive按钮呈灰色,但它们不应该是灰色的。 greyed-out text screen为什么我的文本变灰了?可能上下文与某事有关
我怀疑它与上下文有关,因为一旦我有我的ListView相同的问题。我已经通过将ArrayAdapter的getApplicationContext()引用中的参数更改为getBaseContext()来修复该问题。有人可以向我解释吗?我真的不明白的“语境”
这是我的代码
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("What do you want to do with " + getArrayList("ListOfRecipes").get(position));
builder.setPositiveButton("Delete", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
List<String> list = new ArrayList<>(getArrayList("ListOfRecipes"));
Toast.makeText(getBaseContext(), list.get(position) + "has been removed", Toast.LENGTH_SHORT).show();
list.remove(position);
saveList(list, "ListOfRecipes");
}
});
builder.setNegativeButton("Modify", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
List<String> list = new ArrayList<>(getArrayList("ListOfRecipes"));
SharedPreferences sp = getSharedPreferences("Recip", MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.putString("Recip", list.get(position));
editor.apply();
startActivity(new Intent(getBaseContext(), ManageRecipeActivity.class));
}
});
AlertDialog alertDialog = builder.create();
alertDialog.show();
啊我一直在找那个字。谢谢 – TheD3luxed