Android 在弹出Dialog(带EditText)的同时弹出软键盘并且EditText中的内容全选!!!

AlertDialog.Builder builder = new AlertDialog.Builder(this);
dialog = View.inflate(this, R.layout.dlg_edit_num, null)
builder.setView(dialog); 
editText = (EditText) dialog.findViewById(R.id.dlg_edit_num_etxt_num);
editText.setText(String.valueOf(num));
alertDialog.show();
// 全选
editText.selectAll();
// 显示软键盘
alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
imm.showSoftInput(editText, 0);
imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);

你可能感兴趣的:(android)