wind
wind

Reputation: 63

Android - onConfigurationChanged is not called when keyboard show/hidden

I need to detect hidden key board when hidden keyboard is pressed
My source code

<activity
    android:name="com.teamios.info.activity.MainScreenActivity"
    android:screenOrientation="landscape"
    android:theme="@style/Theme.MyScreenTranNorman"
    android:configChanges="orientation|keyboardHidden"
    android:windowSoftInputMode="stateUnchanged|adjustPan" />

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    Toast.makeText(this, "keyboard visible", Toast.LENGTH_SHORT).show();
}

I tested in samsung galaxy nexus phone android os 4.2.1, but Toast didn't show when keyboard hidden Please help me.

Upvotes: 1

Views: 2849

Answers (2)

John R
John R

Reputation: 2064

 <activity
        android:name="com.teamios.info.activity.MainScreenActivity"
        android:theme="@style/Theme.MyScreenTranNorman"
        android:configChanges="orientation|keyboardHidden"
        android:windowSoftInputMode="stateUnchanged|adjustPan" />

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
    if (newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) {
        Toast.makeText(this, "keyboard visible", Toast.LENGTH_SHORT).show();
    } else if (newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES) {
        Toast.makeText(this, "keyboard hidden", Toast.LENGTH_SHORT).show();
    }
    }

And add

<activity android:name=".MyActivity" android:screenOrientation="landscape " > </activity>

in menifest class.

Upvotes: 1

user1764879
user1764879

Reputation: 122

Did you add android:configChanges="keyboardHidden" in your manifest file ?

Upvotes: 0

Related Questions