Any android event when keyboard slide out

后端 未结 3 493
悲&欢浪女
悲&欢浪女 2020-12-17 04:12

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

Thank you.

相关标签:
3条回答
  • 2020-12-17 04:25

    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.

    0 讨论(0)
  • 2020-12-17 04:28

    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.

    0 讨论(0)
  • 2020-12-17 04:28

    Yes in your Activity override onConfigurationChanged()

    public void onConfigurationChanged(Configuration newConfig){
       if(newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO){
           //slideout detected
       }
    }
    
    0 讨论(0)
提交回复
热议问题