有没有办法告诉如果软键盘显示? [英] Is there a way to tell if the soft-keyboard is shown?

查看:178
本文介绍了有没有办法告诉如果软键盘显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法来告诉我们,如果softkeyboard显示在一个活动或不?

is there a way to tell if the softkeyboard is shown in an activity or not?

我试过

InputMethodManager manager = (InputMethodManager) 
getSystemService(getApplicationContext().INPUT_METHOD_SERVICE);
manager.isActive(v)

isActive 仅在第一次键盘显示之前返回false,但如果kb的出现,然后开除, isActive 返回真也。

but isActive returns false only before the first time the keyboard is shown, but if the kb appears and then dismissed, isActive returns true also.

那么,有没有其他的方法来检查这个问题。

so is there any other method to check for this issue.

感谢

推荐答案

根据这个<一个href="http://groups.google.com/group/android-developers/browse_thread/thread/1c3291f15ed9c044/479f6233b27c5e30?pli=1">POST

您无法检测软键盘显示与否,但可以间接地知道,软键盘显示由明知查看您的活动调整大小。

You cannot detect if soft keyboard is shown or not, but you can indirectly know that a soft key board is shown by knowing that the View of your activity is resized.

假设你有一个的ListView 和底部的的EditText ,你想去的底部当软键盘的用户后,显示列表点击的EditText。

Imagine you have a ListView and at the bottom an EditText, you want to go to the bottom of the list when a soft keyboard is shown after user clicks the EditText.

您需要执行的ListView ,然后用它在你的 ListActivity 活动或查看

You need to implement a subclass of ListView, then use it in your ListActivity or Activity or View.

public class ThreadView extends ListView {

    public ThreadView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
    }

    @Override
    protected void onSizeChanged(int xNew, int yNew, int xOld, int yOld) {
        super.onSizeChanged(xNew, yNew, xOld, yOld);

        if (yOld > yNew) {
            setSelection(((ListAdapter) getAdapter()).getCount() - 1);
        }
    }
}

希望这有助于

Hope this helps

PS。 检查配置更改仅适用于手键盘。

PS. "check Configuration Changes" only works for hand keyboard.

这篇关于有没有办法告诉如果软键盘显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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