onConfigurationChanged()不触发的keyboardHiddenonConfigurationChanged、keyboardHidden

2023-09-05 11:21:01 作者:青春一去沧桑笑、

我已经试过了各种各样的问题和答案在这里设置我的机器人活动覆盖 onConfigurationChanged()以执行的逻辑,当软键盘打开和关闭。下面是我的code中的有关摘录。我煮它归结为最简单的情况:

I've followed the various questions and answers here to setup my Android activity to override the onConfigurationChanged() in order to execute logic when the soft keyboard opens and closes. Here's the relevant excerpts from my code. I've boiled it down to the simplest scenario:

AndroidManifest.xml中

...
<activity 
    android:name=".SearchActivity" 
    android:label="@string/app_name" 
    android:configChanges="keyboard|keyboardHidden|orientation"
/>
...

SearchActivity.java

...
@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    Toast.makeText(this, "onConfigurationChanged()", Toast.LENGTH_SHORT).show();
}
...

在code以上将显示敬酒时,我改变方向,但不执行任何操作,当软键盘打开或关闭。我已经测试通过的EditText打开软键盘聚焦和用的菜单按钮长preSS手动打开它。无论是火 onConfigurationChanged()通话。

所以,code的地方出现,因为方向变化火灾的工作,但我什么也得不到的软键盘。有任何想法吗?如果答案是onConfigurationChanged()不赶软键盘事件,究竟是用来检测和处理这一事件得到妥善解决?

So the code in place appears to work since orientation change fires, but I get nothing for the soft keyboard. Any ideas? If the answer is "onConfigurationChanged() doesn't catch soft keyboard events", what is an appropriate solution for detecting and handling this event?

以防万一,这是相关的,我正在测试一个Droid X的运行姜饼。

Just in case it's relevant, I am testing on a Droid X running Gingerbread.

推荐答案

没有,onConfigurationChange()不赶软键盘事件:它不是一个配置更改。取向变化导致使用一组新的资源(如布局陆VS布局端口),这是一个配置改变的定义。

No, onConfigurationChange() doesn't catch soft keyboard events: it's not a configuration change. The orientation change causes a new set of resources to be used (such as layout-land vs layout-port), which is the definition of a configuration change.

那么怎么办呢?那么,有没有事件触发的键盘显示的时候,但你可以检测到键盘使您的布局进行调整。

So how to do it? Well, There's no event fired when the keyboard is shown, but you can detect when the keyboard causes your layout to be adjusted.

请参阅安卓:是显示软键盘为code?