Android: softkeyboard not showing up

烈酒焚心 提交于 2019-12-01 18:31:50

Try specifying the android:windowSoftInputMode attribute in your AndroidManifest.xml file for your activity.

For example:

<activity android:name=".TestingActivity" android:windowSoftInputMode="stateVisible|adjustResize" />

You probably don't need any of the code that uses InputMethodManager in your Activity.

I notice that one reason for the keyboard not showing up is selecting an inputtype not supported by the specific Android device. For instance InputType.TYPE_NUMBER_VARIATION_NORMAL will not work on my Asus Transformer (no keyboard shows up), while InputType.TYPE_CLASS_NUMBER will work just fine.

    et2.clearFocus();
    et2.requestFocus();
    InputMethodManager mInputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    mInputMethodManager.showSoftInput(et2, InputMethodManager.SHOW_IMPLICIT);

I meet the problem on Android N platform and resolve it by refocusing the editview. I don`t know the real reason why the editview should be cleared first,but it works fine for me.

Sometimes you will need to post-delay showing keyboard command, so in my case, i did the following

editText.postDelayed(new Runnable() {
        @Override
        public void run() {
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
        }
    }, 300);

For getting the focus to particular edittext just add the tag inside your edit text.

<EditText 
    android:id="@+id/etBox"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:hint="enter into editbox"
    >
    <requestFocus/>
    </EditText>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!