当显示由 AlertDialog.Builder 创建的焦点 EditText 的对话框时,是否可以自动显示软键盘?
我已经看过一些关于这个主题的讨论,但我找不到任何可行的解决方案。
答案 0 :(得分:3)
皮肤猫鼬的方法不止一种。
AlertDialog.Builder builder = new AlertDialog.Builder(CurrentActivityName.this);
builder.setTitle(“Title”);
builder.setMessage(“Message”);
etc..
//This is the crucial part
AlertDialog alertDlg = builder.create();
alertDlg.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
alertDlg.show();
手机和平板电脑都很好用
答案 1 :(得分:1)
解决了这个
InputMethodManager imm = (InputMethodManager)
SettingsActivity.this.getSystemService(Context.INPUT_METHOD_SERVICE);
mDialog = mDialogBuilder.create();
mDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
public void onDismiss(DialogInterface dialog) {
dismissSoftKeyboard();
}
});
mPinDialog.show();
showSoftKeyboard();
}
private void showSoftKeyboard() {
if (imm != null) {
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}
}
private void dismissSoftKeyboard() {
if (imm != null) {
imm.toggleSoftInput(InputMethodManager.HIDE_NOT_ALWAYS, 0);
}
}