Search code examples
androidkeyboardandroid-softkeyboardonresumesoft-keyboard

Android soft keyboard displays weirdly after calling onResume


I have an EditText that I manually control showing keyboard by below code:

private void showKeyboard(boolean show) {
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    if (show) {
        mAddNewEditText.requestFocus();
        imm.showSoftInput(mAddNewEditText, 0);
    } else {
        mAddNewEditText.clearFocus();
        imm.hideSoftInputFromWindow(mAddNewEditText.getWindowToken(), 0);
    }
}

Opened the keyboad

I'll call implicit intent to gets a new image and when it goes back to activity, it wont show the soft keyboard. So I tried to show the keyboard onResume function as below:

@Override
protected void onResume() {
    super.onResume();
    if (mAddNewEditText.isFocused()) {
        mAddNewEditText.post(
                () -> showKeyboard(true)
        );
    }
}

but it shows the keyboard like this which is different than normally showing the keyboard:

soft keyboard shows weirdly

I'm wondering what is the problem here. Is it because I'm using post method? without post I cannot show keyboard!

What have I tried:

  • I tried to use without post which doesn't show the keyboard.
  • I tried to call imm.showSoftInput(txtPassword, 0); which result the same.
  • I tried mAddNewEditText.postDelayed method with 100 result the same.
  • I tried putting android:windowSoftInputMode="stateVisible" on Menifest result the same.

Note: I'm using Android emulator.


Solution

  • Okay I found the answer: in my styles.xml I had this code :

    <item name="android:windowFullscreen">true</item>
    

    which caused the problem, not sure why.