我正在使用 AppCompat 支持库为 pre-L(恰好是 API 9+)设备创建一个应用程序。 我遇到的问题与 AppCompat 的抽屉导航有关:如果我的布局中有一个抽屉并且我正在初始化它,那么我的 fragment 中的所有 EditText 元素都无法聚焦(它们会在一瞬间获得焦点,然后它们失去它;软键盘没有出现)。
我只使用一个加载 fragment 的 Activity :
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/toolbar"/>
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:foreground="?android:windowContentOverlay">
<View
android:layout_width="match_parent"
android:layout_height="4dp"
android:background="@drawable/toolbar_shadow"/>
<FrameLayout
android:id="@+id/app_fragment"
android:layout_below="@id/toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/scan_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_margin="16dp"
android:clickable="true"
android:src="@drawable/ic_scan"
app:borderWidth="0dp"
app:elevation="4dp"/>
</RelativeLayout>
</LinearLayout>
<include layout="@layout/drawer_content"/>
我在没有初始化抽屉的情况下测试了代码,一切正常。知道是什么导致了这个问题吗?
最佳答案
所以我发现了问题所在。我不知道为什么,可能是因为触摸事件是通过抽屉进行的,我在我的代码中有这一行,它禁用了 DrawerLayout 下所有内容的任何事件:
drawer.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
关于android - AppCompat 抽屉导航不让我关注任何 EditText,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32424332/