我已经试过了 this solution但是 onGlobalLayout()
永远不会被调用。
是的,我已经在 list 中设置了 android:windowSoftInputMode="adjustResize"
。
可能是因为我正在使用 DrawerLayout
作为我的 Activity 根布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- The main content view -->
<LinearLayout
android:id="@+id/main_fragment_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" />
<!-- The navigation drawer -->
<LinearLayout
android:id="@+id/user_fragment_layout"
android:layout_width="200dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:orientation="vertical" >
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
我已经在 findViewById()
中测试了 activity_drawer_layout
和 main_fragment_layout
但没有成功; onGlobalLayout()
永远不会被调用。请帮我。提前致谢。
最佳答案
我不太确定你想通过识别你的键盘是否可见来实现什么,但是如果你只想在打开抽屉导航时隐藏键盘,我建议你使用下面的代码
private void hideKeyboard() {
// Check if no view has focus:
View view = this.getCurrentFocus();
if (view != null) {
InputMethodManager inputManager = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
}
你也看过How to check visibility of software keyboard in Android?吗?
关于android - 使用抽屉导航检测键盘是否显示在 android 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27383999/