Why doesn't the softKeyboard open when I tap an editText inside a ViewPager?

心不动则不痛 提交于 2019-12-25 07:44:40

问题


Like the title says, I've got a viewPager with some editText fields inside. I can select the editText fields perfectly fine (emulator and physical device). I see the cursor, and I see the underline color change, indicating it's selected, but I can't type. Tapping on the editText fields doesn't open the softKeyboard.

Is this a known issue with a simple fix, or is code needed to identify what's going wrong here?


回答1:


Finally bumped in to an answer that's working for me, which can be found here.


Basically, if you're using the onCreateDialog() method, you leave that as is, and add the onResume() method below to your DialogFragment's java file.

@Override
public void onResume() {
    super.onResume();
    Dialog dialog = getDialog();
    dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
}



回答2:


You can force softKeyboard with this code:

EditText yourEditText= (EditText) findViewById(R.id.yourEditText);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);


来源:https://stackoverflow.com/questions/36228949/why-doesnt-the-softkeyboard-open-when-i-tap-an-edittext-inside-a-viewpager

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!