1

我有一个属性设置为android:inputType="number". 现在,如果我专门触摸编辑框,我会得到数字键盘。但是当我以编程方式聚焦时,会出现 qwerty 键盘。

InputMethodManager m = (InputMethodManager) context
                .getSystemService(Context.INPUT_METHOD_SERVICE);

显示了简单的 qwerty 键盘。如果我想打开数字键盘怎么办?

4

2 回答 2

1

要显示键盘:

InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.showSoftInput(viewToEdit, 0);

隐藏键盘:

if (getCurrentFocus() != null) {
    inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getApplicationWindowToken(), 0);
}
于 2013-09-10T13:31:40.627 回答
0

这应该可以帮助您:

    yourEditText.performClick();
于 2013-09-10T13:24:08.413 回答