我已将抽屉导航添加到我的应用程序中。到目前为止,其他一切都很好,但我遇到了一个问题,即当抽屉导航打开时键盘没有关闭。抽屉导航是主要 Activity ,然后从抽屉打开的每个页面都是一个 fragment 。
我尝试将以下内容添加到 fragment 中的每个 EditText 区域。然而,这并没有关闭任何东西。
InputMethodManager imm1 = (InputMethodManager)getActivity().getSystemService(
Context.INPUT_METHOD_SERVICE);
imm1.hideSoftInputFromWindow(input1.getWindowToken(), 0);
我也曾尝试将该代码放在主要 Activity 中,但也没有成功。关于我可以做些什么来使它正常工作有什么想法吗?
最佳答案
要在打开或关闭抽屉导航时隐藏打开的键盘,请覆盖 onDrawerListner
中的方法 onDrawerSlide
并添加以下行
InputMethodManager inputMethodManager = (InputMethodManager) actionBarActivity
.getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(
actionBarActivity.getCurrentFocus().getWindowToken(),
0
);
关于android - 抽屉导航打开时如何关闭键盘?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18430186/