3

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

Aleadam
  • 40,203
  • 9
  • 86
  • 108
mikepenz
  • 12,708
  • 14
  • 77
  • 117

1 Answers1

0

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

Aleadam
  • 40,203
  • 9
  • 86
  • 108
  • BTW, there is a related question here: http://stackoverflow.com/questions/2150078/android-is-software-keyboard-shown with an answer using an indirect method relying on the change of size of your layout. – Aleadam May 13 '11 at 19:35