我制作了一个自定义alertDialog并且在其中我放了一个EditText,但问题是当我点击EditText写输入时键盘不会显示!
这是我的警告对话框类:
public class EditTaskDialog extends AlertDialog {
Activity mParent;
public EditTaskDialog(Context context, Activity parent) {
super(context);
mParent = parent;
}
@BindView(R.id.btn_edit_edti_task_dialog)
Button btn_edit_edti_task_dialog;
@BindView(R.id.tv_time_edit_task_dialog)
TextView tv_time_edit_task_dialog;
@BindView(R.id.ll_time_edit_task_dialog)
LinearLayout ll_time_edit_task_dialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//the layout that have the edit text view
setContentView(R.layout.edit_task_dialog);
ButterKnife.bind(this);
final DatePickerDialog.OnDateSetListener x = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
tv_time_edit_task_dialog.setText(dayOfMonth+ "/" + (month+1) +"/"+ year);
}
};
ll_time_edit_task_dialog.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new DatePickerDialog(
mParent,
x,
Calendar.getInstance().get(Calendar.YEAR),
Calendar.getInstance().get(Calendar.MONTH),
Calendar.getInstance().get(Calendar.DAY_OF_MONTH)
).show();
}
});
}
}
请注意我不能使用getSystemService(),因为它连接到启动alertDialog的活动,所以当我像这样使用它时
InputMethodManager imm = (InputMethodManager) mParent.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
键盘显示在警告对话框后面和开始活动
之前答案 0 :(得分:0)
我修复了问题而不是使用AlertDialog我使用了Dialog Class