HOWTO捕获“虚拟键盘显示/隐藏”在Android的事件? [英] Howto capture the 'virtual keyboard show/hide' event in Android?

查看:173
本文介绍了HOWTO捕获“虚拟键盘显示/隐藏”在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.

<一个href="http://developer.android.com/guide/topics/resources/runtime-changes.html#HandlingTheChange">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.

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

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