我正在使用9+支持库为预L(确切地说是API AppCompat )设备创建一个应用程序。我遇到的问题与AppCompat的导航抽屉有关:如果我的布局中有一个抽屉,并且我正在初始化它,那么我的片段中没有一个EditText elemenet无法聚焦(它们会在短时间内获得fosus,然后就会丢失;软键盘不会出现)。
我只使用一个将片段加载到其中的活动:
<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"/>
我在没有初始化抽屉的情况下测试了代码,一切都很好。知道是什么导致了这个问题吗?
发布于 2015-09-11 02:08:32
所以我找到了问题所在。我不知道为什么,可能是因为触摸事件通过了抽屉,在我的代码中有一行在DrawerLayout下禁用所有事件:
drawer.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
https://stackoverflow.com/questions/32424332
复制相似问题