有没有办法告诉如果软键盘显示?没有办法、键盘

2023-09-12 02:07:39 作者:  舞↘唯Se彩巛

有没有办法来告诉我们,如果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.

感谢

推荐答案

根据这个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.