如何在Android中检测软键盘 [英] How to detect Soft Keypad in Android

查看:53
本文介绍了如何在Android中检测软键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天!

如何检测android中的软键盘是否已激活.

我特地尝试使用这种代码,并伤心地说,它仅检测了android的软键盘的失活.

Good day!

How can I detect if soft keypad in android has been activated.

I''ve tried using this kind of code and sad to say, it detects only for deactivation of soft keypad in android.

final View activityRootView = findViewById(R.id.activityRoot);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
    @Override
    public void onGlobalLayout() {
        int heightDiff = activityRootView.getRootView().getHeight() - activityRootView.getHeight();
        if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard but it does not work.
            ... do something here (what i just did was to display a string "ACTIVATED")
        }
        else     //it will work
        {
          ... do something here (what i just did was to display a string "DEACTIVATED")
        }
     }
});



请帮助我解决这个问题.
:(

更大的力量,谢谢! :)



Please help me get through with tihs problem.
:(

More power and thanks! :)

推荐答案

http://stackoverflow.com/questions/4747417/android-how-to-detect-soft-keyboard-shown-in-the-screen [
http://stackoverflow.com/questions/2150078/how-to-check-visibility-of-software-keyboard-in-android[^]
http://stackoverflow.com/questions/4747417/android-how-to-detect-soft-keyboard-shown-in-the-screen[^]


这篇关于如何在Android中检测软键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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