[英]Any android event when keyboard slide out
Is there any intent/event that i can listen to when user slide out the keyboard on a phone with keyboard? 当用户在带键盘的手机上滑出键盘时,我可以听到任何意图/事件吗?
Thank you. 谢谢。
in your Manifest file, add this to your activity definition: android:configChanges="keyboard|keyboardHidden"
在您的清单文件中,将其添加到您的活动定义: android:configChanges="keyboard|keyboardHidden"
and in your Activity java file, override the method onConfigurationChanged
: 并在您的Activity java文件中,重写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. 当键盘事件在此活动中触发时,将调用此方法,您可以执行任何操作。
There is an ACTION_CONFIGURATION_CHANGED
broadcast you can listen to. 您可以收听ACTION_CONFIGURATION_CHANGED
广播。 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. @schwiz和@binnyb提供的解决方案存在一个重大缺陷 - 它们迫使您处理配置更改的所有实际工作。 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. 这可能是必要的,但你可以更好地服务于不覆盖android:configChanges
,并使用onSaveInstanceState()
和onRetainNonConfigurationInstance()
来处理实际的配置更改。
Yes in your Activity override onConfigurationChanged()
在您的Activity覆盖onConfigurationChanged()
public void onConfigurationChanged(Configuration newConfig){
if(newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO){
//slideout detected
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.