Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any android event when keyboard slide out

Tags:

android

Is there any intent/event that i can listen to when user slide out the keyboard on a phone with keyboard?

Thank you.

like image 828
michael Avatar asked Feb 18 '11 21:02

michael


3 Answers

in your Manifest file, add this to your activity definition: android:configChanges="keyboard|keyboardHidden"

and in your Activity java file, override the method onConfigurationChanged:

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    if(newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) {
       //handle keyboard slide out event
    }
    else if(newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES)
        //handle keyboard slide in event
    }
}

when a keyboard event fires off in this activity, this method will be called and you can do whatever you want.

like image 62
james Avatar answered Nov 14 '22 08:11

james


There is an ACTION_CONFIGURATION_CHANGED broadcast you can listen to. The solutions provided by @schwiz and @binnyb have a major flaw -- they force you to deal with all of the actual work of the configuration change. That may be necessary, but you are far better served not overriding android:configChanges, and using onSaveInstanceState() and onRetainNonConfigurationInstance() for handling the actual configuration change.

like image 38
CommonsWare Avatar answered Nov 14 '22 08:11

CommonsWare


Yes in your Activity override onConfigurationChanged()

public void onConfigurationChanged(Configuration newConfig){
   if(newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO){
       //slideout detected
   }
}
like image 1
Nathan Schwermann Avatar answered Nov 14 '22 09:11

Nathan Schwermann