开发者

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, l开发者_如何学编程ike hide some visual elements, if the SoftKeyboard so a Input like Swipe or the normal Android Keyboard is shown.

I've tried the onConfigurationChange="KeyboardShow" (pseudocode) but had no change to get a event when for example skype got shown.

So now my question is, is there any solution or function or listener, with which i can handle such a action?

I hope someone can help me.

Sincerly, Mike Penz


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

static Configuration prevConf = Configuration();
static int ignoreMasks = Configuration.HARDKEYBOARDHIDDEN_NO|Configuration.HARDKEYBOARDHIDDEN_YES;

onCreate() {
   prevConf = setToDefaults();
}
// all your code here

@Override
public void onConfigurationChanged (Configuration newConfig) {
    int deltas = 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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜