Android在拥有EdittExt的Activity界面,一般都会自动弹出键盘,有时我们需要设置EdittExt的一个父View来设置他们的
android:focusable=”true”
android:focusableInTouchMode=”true”即可。
而在Dialog中,他不会自动弹出键盘,我们呢又需要他自动弹出来。所以就有了这样一个问题。解决方案如下:
final EditText mETPassWord = (EditText) layout.findViewById(R.id.et_dialog_confirmphoneguardpswd);mETPassWord.setFocusable(true);mETPassWord.setFocusableInTouchMode(true);mETPassWord.requestFocus();Timer timer = new Timer();//用TImer定时器异步加载是考虑到在Dialog初始化完成之前调用showSoftInput方法不会生效,timer.schedule(new TimerTask() {public void run() {InputMethodManager inputManager = (InputMethodManager) mETPassWord.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);inputManager.showSoftInput(mETPassWord, 0);}}, 500);