onInputShowListener Android - Is it possible to detect if any soft keyboard is shown?

放肆的年华 提交于 2020-01-04 01:55:32

问题


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 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


回答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

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



来源:https://stackoverflow.com/questions/5995272/oninputshowlistener-android-is-it-possible-to-detect-if-any-soft-keyboard-is-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!