android - AppCompat 抽屉导航不让我关注任何 EditText

标签 android android-fragments navigation-drawer

我正在使用 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/

相关文章:

android - 如何在android中创建弹出模式窗口

javascript - 展会推送 :android:upload is not supported in the local CLI, 请使用 eas 凭证

java - 全局布局监听器返回 0

android - 如何使用菜单布局将自定义项添加到 NavigationView?

android - 将 AutoCompleteTextView 下拉高度设置为底部上方 60dp

android - 无法向关闭的应用程序发送广播

android - 是否可以将持久 Bottom Sheet 作为 fragment ?

java - Android - AlertDialog 中的字符串值在访问时不断重置

android - 如何创建带有抽屉导航的自定义 ActionBar?

android - 在 android Activity 的抽屉导航中显示联系人