如何知道,如果键盘(DIS)将出现在Android的? [英] How to know if keyboard (dis)appears in Android?

查看:155
本文介绍了如何知道,如果键盘(DIS)将出现在Android的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个EditText和想要的键盘出现时,给它更多的线路。
所以我要寻找像一个的OnKeyboardAppearsListener的,但无法找到它。
我想它一定存在,但可能以不同的方式...

I have an EditText and want to give it more lines when the keyboard appears. So i am looking for something like a "OnKeyboardAppearsListener" but can't find it. I think it must exist, but perhaps in a different way...

推荐答案

您需要的 @覆盖 onConfigurationChanged 来能够处理运行时更改

You have to @Override onConfigurationChanged to be able to handle runtime changes:

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

    // Checks whether a hardware or on-screen keyboard is available
    if (newConfig.keyboardHidden == Configuration.KEYBOARDHIDDEN_NO) {
        Toast.makeText(this, "Keyboard visible", Toast.LENGTH_SHORT).show();
    } else if (newConfig.keyboardHidden == Configuration.KEYBOARDHIDDEN_YES) {
        Toast.makeText(this, "Keyboard hidden", Toast.LENGTH_SHORT).show();
    }
}

从这里 拍摄的实施例。这里看看相关(其中包括)键盘字段,你可能需要使用。

Example taken from here. Take a look here for keyboard related (among others) fields you might want to use.

编辑(RivieraKid):改为考虑硬或屏幕键盘

Edit (RivieraKid): Changed to take account of hard or on-screen keyboard.

这篇关于如何知道,如果键盘(DIS)将出现在Android的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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