有没有办法在EditText获取焦点时通过编程告诉Android打开键盘?
另外,有没有办法告诉它打开数字键盘?
谢谢 Victor
另外,有没有办法告诉它打开数字键盘?
谢谢 Victor
在布局中创建编辑文本字段:
(如果您想使用QWERTY键盘,则无需此步骤)
<EditText
...
android:inputType="number"
... />
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
最重要的是在 onResume 方法中专注于编辑文本。
@Override
public void onResume() {
super.onResume();
editText.setFocusableInTouchMode(true);
editText.requestFocus();
}
要将其转化为数字,请使用以下内容
text.setInputType(InputType.TYPE_CLASS_NUMBER);
显示键盘:
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.showSoftInput(viewToEdit, 0);
如何隐藏键盘:
if (getCurrentFocus() != null) {
inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getApplicationWindowToken(), 0);
}