如何捕捉“虚拟键盘显示/隐藏” Android中的活动? [英] How to capture the "virtual keyboard show/hide" event in Android?

查看:190
本文介绍了如何捕捉“虚拟键盘显示/隐藏” Android中的活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据是否显示虚拟键盘来更改布局。我搜索了API和各种博客,但似乎找不到任何有用的东西。

I would like to alter the layout based on whether the virtual keyboard is shown or not. I've searched the API and various blogs but can't seem to find anything useful.

可以吗?

谢谢!

推荐答案

你必须自己处理配置更改。

You've got to handle configuration changes yourself.

http://developer.android.com/ guide / topics / resources / runtime-changes.html#HandlingTheChange

示例:

// from the link above
@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);


    // 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();
    }
}

然后只是更改一些视图的可见性,更新字段,并更改您的布局文件。

Then just change the visibility of some views, update a field, and change your layout file.

此解决方案不适用于软键盘和 onConfigurationChanged 不会用于软键盘。

This solution will not work for soft keyboards and onConfigurationChanged will not be called for soft keyboards.

这篇关于如何捕捉“虚拟键盘显示/隐藏” Android中的活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆