如何隐藏默认键盘菜单上单击时? [英] How to hide default keyboard when click on menu?
本文介绍了如何隐藏默认键盘菜单上单击时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经插入了 onCreateOptionsMenu(菜单菜单)在code
没有成功尝试本网站的几种方法。我想隐藏键盘当我点击菜单按钮。
I have tried several methods for this website by inserting the code in the onCreateOptionsMenu (Menu menu)
without success. I want to hide the keyboard when I click the menu button.
我有三个,其中的EditText我写一些数据,并选择插入/删除/修改数据库,在菜单上,但如果我点击,键盘不会自动隐藏。
I have three EditText where I write some data, and options to insert / delete / modify a database, are on the menu, but if I click, the keyboard does not hide automatically.
我有这样的事情:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
if(this.getCurrentFocus() != null && this.getCurrentFocus() instanceof EditText){
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
return true;
}
它只能我第一次preSS菜单按钮。
It only works the first time I press the menu button.
谢谢!
推荐答案
移动code到 onOptionsItemSelected
而不是
public boolean onOptionsItemSelected(MenuItem item) {
.....
if(this.getCurrentFocus() != null && this.getCurrentFocus() instanceof EditText){
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
return super.onOptionsItemSelected(item);
}
这篇关于如何隐藏默认键盘菜单上单击时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文