有没有办法判断软键盘是否显示?

Min*_*amy 16 android

有没有办法判断软键盘是否显示在活动中?

我试过了

InputMethodManager manager = (InputMethodManager) 
getSystemService(getApplicationContext().INPUT_METHOD_SERVICE);
manager.isActive(v)
Run Code Online (Sandbox Code Playgroud)

isActive仅在第一次显示键盘之前返回false,但如果kb出现然后被解除,则isActive也返回true.

那么有没有其他方法来检查这个问题.

谢谢

Div*_*nto 13

根据这个POST

您无法检测是否显示软键盘,但您可以通过了解View活动的大小来间接地知道显示软键盘.

想象一下,你有一个ListView在底部的EditText,你想去到列表的底部,当用户点击后的EditText显示软键盘.

你需要实现一个子类ListView,然后在你的ListActivityor Activity或中使用它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);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助

PS."检查配置更改"仅适用于手持键盘.