您的位置:首页 > 移动开发 > Android开发

Android弹出式对话框AlertDialog中的EditText自动打开软键盘

2017-03-13 16:26 399 查看
private void confirmPhoneGurdPswd(final String guardPswd) {

// 1.创建弹出式对话框
final AlertDialog.Builder alertDialog = new android.app.AlertDialog.Builder(HomeActivity.this); // 系统默认Dialog没有输入框

// 获取自定义的布局
View alertDialogView = View.inflate(HomeActivity.this, R.layout.自定义布局, null);

// 2.密码框-EditText。alertDialogView.findViewById(R.id.自定义布局中的文本框)
final EditText et_dialog_confirmphoneguardpswd = (EditText) alertDialogView.findViewById(R.id.et_dialog_confirmphoneguardpswd);

// 确认按钮,确认验证密码
Button btn_dialog_resolve_confirmphoneguardpswd = (Button) alertDialogView.findViewById(R.id.btn_dialog_resolve_confirmphoneguardpswd);
btn_dialog_resolve_confirmphoneguardpswd.setOnClickListener(new OnClickListener() {
// 点击按钮处理
public void onClick(View v) {
// 提取文本框中输入的文本密码
}
});
// 取消按钮,不验证密码
Button btn_dialog_cancel_confirmphoneguardpswd = (Button) alertDialogView.findViewById(R.id.btn_dialog_cancel_confirmphoneguardpswd);
btn_dialog_cancel_confirmphoneguardpswd.setOnClickListener(new OnClickListener() {
// 点击按钮处理
public void onClick(View v) {
//
}
});

AlertDialog tempDialog = alertDialog.create();
tempDialog.setView(alertDialogView, 0, 0, 0, 0);

/** 3.自动弹出软键盘 **/
tempDialog.setOnShowListener(new OnShowListener() {
public void onShow(DialogInterface dialog) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(et_dialog_confirmphoneguardpswd, InputMethodManager.SHOW_IMPLICIT);
}
});

tempDialog.show();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐