android - 抽屉导航在onDrawerOpened时隐藏键盘

标签 android navigation-drawer

我有一个带有编辑文本的 fragment 。 当我单击edittext时,键盘出现。 问题是当我打开抽屉时,抽屉并没有隐藏键盘。 即使我切换到另一个 fragment ,键盘仍然显示。 打开抽屉时如何隐藏键盘。

我试着放

InputMethodManager imm = 
                        (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(getWindowToken(), 0);

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

两者都不隐藏键盘。

最佳答案

在打开/关闭滑动抽屉之前使用这行代码:

InputMethodManager inputMethodManager = (InputMethodManager)  this.getSystemService(Activity.INPUT_METHOD_SERVICE);
    inputMethodManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), 0);

关于android - 抽屉导航在onDrawerOpened时隐藏键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17515839/

相关文章:

android - 使用 OnClickListener 在同一 Activity 中的 Facebook Twitter 按钮

Android sticky-footer : Align footer view to table, 直到达到屏幕大小,然后固定在底部

android - 无法将调试器连接到 Jelly Bean Galaxy Nexus

android - 当字符串包含 "-"时无法删除 sqlite 中的特定行

android - 抽屉导航的自定义动画

android - RadioGroup 中 RadioButtons 之间的分隔符 - 类似于 GMail 的

android - 如何使用设计支持库将页脚添加到 Android 中的抽屉导航?

android - DrawerLayout 内容中的 ScrollView 防止滑动打开抽屉

java - 为什么 RGBA 位图需要 3x3 数组来存储 1 个像素,如何避免这种情况?

java - Android:没有xml的抽屉导航