如何禁用 MaterialAlertDialogBuilder 中的按钮?我想在此屏幕截图中制作类似的功能: 在此处输入图像描述
我编写了以下代码(对话框包含 EditText,用户应在其中输入他最喜欢的食物名称)。
final MaterialAlertDialogBuilder dialogEnterDishName = new MaterialAlertDialogBuilder(context);
//...
final EditText editTextEnterDishName = new EditText(context);
dialogEnterDishName.setView(editTextEnterDishName);
dialogEnterDishName.setPositiveButton(getString(R.string.dialog_enter_dish_name_positive_button), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (!editTextEnterDishName.getText().toString().equals(""))
//...
else {
//TODO Make posititve button disabled until the user enters any character
}
}
});
//...
dialogEnterDishName.show();
}
我已经知道,AlertDialog 类(MaterialAlertDialogBuilder extends AlertDialog.Builder)有一个方法 public Button getButton(int whichButton)
,但我不能在 MaterialAlertDialogBuilder 中使用它。
请帮忙!