我是java android的新手。我使用EditText读取数字,其中inputType设置为“number”。当我点击它时,会显示一个虚拟键盘。按下键V(验证密钥)后如何关闭键盘谢谢
这是方法,您应该创建一个帮助方法,然后通过传递适用的上下文来调用它。
在您想要的事件发生后调用此方法。
public static void hideKeyboard(Activity activity) {
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
//Find the currently focused view, so we can grab the correct window token from it.
View view = activity.getCurrentFocus();
//If no view currently has focus, create a new one, just so we can grab a window token from it
if (view == null) {
view = new View(activity);
}
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}