带 ListView 的 DrawerLayout 不处理三星 Tab/Android 5.0.2 上的项目点击

DrawerLayout with ListView does not process item clicks on Samsung Tab/Android 5.0.2

我在主 activity(扩展了 AppCompatActivity)中使用带有 com.android.support:appcompat-v7 的 android.support.v4.widget.DrawerLayout 来提供导航抽屉和抽屉中的 ListView 以呈现用户可点击的项目。

除了 Samsung Tab 设备 运行 Android 5.0.2.

代码已经过测试,可以在 4.2.1 到 6.0.1 的各种 Android 版本上按预期工作,并且在模拟器 运行 5.0.2.[=14 上工作正常=]

在 Samsung 设备上,导航抽屉会在点击时关闭,但新的 activity(例如下面代码中的 MyPreferenceActivity 或 HelpPageActivity)永远不会显示。

我的问题:代码或布局是否有任何不正确之处可能导致此功能无法在三星 Tab/5.0.2 设备上运行?

主要activity如下:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent" android:gravity="fill"
    android:background="@color/standard_bkgnd">

<include
    android:id="@+id/toolbar_actionbar"
    layout="@layout/toolbar_actionbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

<android.support.v4.widget.DrawerLayout
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@id/toolbar_actionbar"
    >

    <!-- normal content view -->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        ...main UI stuff...
    </LinearLayout>

    <!-- drawer view -->
    <include layout="@layout/nav_drawer" />

</android.support.v4.widget.DrawerLayout>

</LinearLayout>

nav_drawer布局如下:

    <RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="280dp"
    android:layout_height="match_parent"
    android:background="@color/button_material_dark"
    android:orientation="vertical"
    android:layout_gravity="start">

    <RelativeLayout
        android:id="@+id/drawer_header"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:background="@color/material_blue_grey_800"
        android:padding="8dp" >

        <ImageView
            android:id="@+id/app_icon"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:src="@drawable/ic_launcher_08"
            android:layout_marginTop="15dp"
            android:contentDescription="@string/app_icon"/>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="42dp"
            android:layout_centerVertical="true"
            android:layout_marginLeft="15dp"
            android:layout_toRightOf="@+id/app_icon"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/app_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/app_name"
                android:textColor="#fff"
                android:textSize="16sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/desc"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom"
                android:layout_marginTop="4dp"
                android:text="@string/app_long_name"
                android:textColor="#fff"
                android:textSize="12sp" />
        </LinearLayout>
    </RelativeLayout>

    <ListView
        android:id="@+id/nav_list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/drawer_header"
        android:choiceMode="singleChoice"/>

</RelativeLayout>

ListView 配置为显示多个项目,用户可以单击这些项目来查看应用内的其他内容,或执行其他活动:

// Drawer Item click listeners
    drawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            switch (position) {
                case 0: // preferences
                    startActivity(new Intent(that, MyPreferenceActivity.class));
                    break;
                case 1: // help
                    startActivity(new Intent(that, HelpPageActivity.class));
                    break;
                case 2: // send feedback
                    composeEmail();
                    break;
                default:
                    break;
            }

            _drawerLayout.postDelayed(new Runnable() {
                @Override
                public void run() {
                    _drawerLayout.closeDrawers();
                }
            }, 500);

            drawerList.clearChoices();

        }
    });

非常感谢任何建议!

所以,事实证明这与三星没有任何关系 Tab/5.0.2 毕竟 - 巧合的是,我唯一报告的问题来自这些设备。

问题是我的主 activity 有一个横向布局,它具有正常内容视图和抽屉视图的顺序 reversed,这阻止了接收点击事件的列表项:

<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/toolbar_actionbar"
>

<!-- normal content view -->
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    ...main UI stuff...
</LinearLayout>

<!-- drawer view *** this must come after the normal content view *** -->
<include layout="@layout/nav_drawer" />

</android.support.v4.widget.DrawerLayout>

我一切换它们,一切就按预期进行了。朵.