我试图用java编程隐藏数字键盘,我在按钮的onClick
中使用了这段代码。
InputMethodManager inputMethodManager =(InputMethodManager)getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
但是,当用户第一次单击数字键盘时,数字键盘变成字符串键盘(普通键盘),当用户第二次单击键盘隐藏时。我要把键盘隐藏起来,第一次点击,有帮助吗?
发布于 2022-01-26 21:30:45
尝试使用以下代码隐藏键盘:
/*--for hiding keyboard on click--*/
InputMethodManager imm=(InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
//Find the currently focused view, so we can grab the correct window token from it.
View view3=getCurrentFocus();
//If no view currently has focus, create a new one, just so we can grab a window token from it
if (view3==null){
view3=new View(this);
}
assert imm != null;
imm.hideSoftInputFromWindow(view3.getWindowToken(), 0);
https://stackoverflow.com/questions/70857457
复制相似问题