Saba
Saba

Reputation: 1541

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:

Note: I'm using Android emulator.

Upvotes: 2

Views: 873

Answers (3)

Saba
Saba

Reputation: 1541

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.

Upvotes: 1

Gavin Zhuang
Gavin Zhuang

Reputation: 74

Maybe you can try postDelayed(), delay 500 milliseconds or more. Ensure show keyboard after UI completed.

Upvotes: 1

Mahesh Gawhane
Mahesh Gawhane

Reputation: 338

put this line in your manifest inside activity

<aplication>
   <activity
        android:windowSoftInputMode="stateHidden|adjustResize"/>
 </aplication>

Upvotes: 1

Related Questions