Skip to content Skip to sidebar Skip to footer

Oninputshowlistener Android - Is It Possible To Detect If Any Soft Keyboard Is Shown?

after fixing another problem in my Android Application, i came to another thing. It would be important that i can do something, like hide some visual elements, if the SoftKeyboard

Solution 1:

There might be better approaches, but a possibility is to add: android:configChanges="keyboardHidden" to the manifest. That will fire with any keyboard changes, so the you will need to query the Configuration object

staticConfigurationprevConf= Configuration();
staticintignoreMasks= Configuration.HARDKEYBOARDHIDDEN_NO|Configuration.HARDKEYBOARDHIDDEN_YES;

onCreate() {
   prevConf = setToDefaults();
}
// all your code here@OverridepublicvoidonConfigurationChanged(Configuration newConfig) {
    intdeltas= newConfig.diff (prevConf); // what changed?
    prevConf = newConfig;

    if (delta & ignoreMasks) 
        return; // you're not interested in hard keyboards.//  your code here 
}

I suck at bitwise operators, so you might need to work around that.

This is the API documentation:

http://developer.android.com/reference/android/R.attr.html#configChanges

http://developer.android.com/reference/android/app/Activity.html#onConfigurationChanged%28android.content.res.Configuration%29

http://developer.android.com/reference/android/content/res/Configuration.html

Post a Comment for "Oninputshowlistener Android - Is It Possible To Detect If Any Soft Keyboard Is Shown?"