“方向|键盘隐藏”不调用 onConfigurationChanged

发布于 2024-10-11 06:13:55 字数 153 浏览 2 评论 0原文

我想知道键盘何时关闭,因此我使用 android:configChanges="orientation|keyboardHidden"。我必须重写该方法 onConfigurationChanged,但似乎什么也没有发生。我做错了什么吗?

I want to know when the keyboard is closed, so I'm using android:configChanges="orientation|keyboardHidden". I have to override the method
onConfigurationChanged, but nothing seems to happen. Am I doing something wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜尕妞 2024-10-18 06:13:55

观看日期,可能您有问题的解决方案,否则:

这是我对另一个相关问题所做的相同答复:有没有办法判断软键盘是否显示?

但我在这里复制了部分响应避免死链接:

这是一个特定的示例

检查以更好地理解http://developer.android.com/guide/topics/resources/runtime-changes.html

文档中的代码:

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    // Checks the orientation of the screen
    if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
        Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
    } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
        Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
    }
    // Checks whether a hardware keyboard is available
    if (newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) {
        Toast.makeText(this, "keyboard visible", Toast.LENGTH_SHORT).show();
    } else if (newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES) {
        Toast.makeText(this, "keyboard hidden", Toast.LENGTH_SHORT).show();
    }
}

watching the date , possibly you have a solution for your question, otherwise:

Here is the same response i made to another question related : Is there a way to tell if the soft-keyboard is shown?

but i copy a portion of the response here to avoid dead links:

Here is a specific sample:

Check for better understanding http://developer.android.com/guide/topics/resources/runtime-changes.html

Code from docs:

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    // Checks the orientation of the screen
    if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
        Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
    } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
        Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
    }
    // Checks whether a hardware keyboard is available
    if (newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) {
        Toast.makeText(this, "keyboard visible", Toast.LENGTH_SHORT).show();
    } else if (newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES) {
        Toast.makeText(this, "keyboard hidden", Toast.LENGTH_SHORT).show();
    }
}
北音执念 2024-10-18 06:13:55

您是否在重写的方法中添加了 super.onConfigurationChanged(newConfig);

Have you added super.onConfigurationChanged(newConfig); in the overridden method?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文