Android EditText,软键盘显示/隐藏事件? [英] Android EditText, soft keyboard show/hide event?

查看:46
本文介绍了Android EditText,软键盘显示/隐藏事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以捕获为 EditText 显示或隐藏软键盘的事件?

Is it possible to catch the event that Soft Keyboard was shown or hidden for EditText?

推荐答案

我使用了以下解决方法:

Hi I'd used following workaround:

就我的内容视图是 LinearLayout 的子类(可以是任何其他视图或视图组)而言,我重写了 onMeasure 方法,如下所示:

As far as my content view is a subclass of LinearLayout (could be any other view or view group), I'd overridden onMeasure method lilke following:

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    final int proposedheight = MeasureSpec.getSize(heightMeasureSpec);
    final int actualHeight = getHeight();

    if (actualHeight > proposedheight){
        // Keyboard is shown
    } else {
        // Keyboard is hidden
    }

    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}

这个解决方法帮助我在键盘显示时隐藏了一些控件,否则会恢复.

This workaround helped me to hide some controls when keyboard is showing and bring back otherwise.

希望这会有用.

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

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