使用NavigationView的DrawerLayout - 未在点击上显示涟漪效应

mic*_*sol 6 android navigation-drawer drawerlayout navigationview android-navigationview

我在抽屉上看到可以看到点击效果的问题.

我有活动xml布局如下:

    <?xml version="1.0" encoding="utf-8"?>
<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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <include
        layout="@layout/app_bar_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer"/>

</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)

你可以看到我放入NavigationView我的DrawerLayout然后NavigationView使用菜单xml文件填充.

activity_main_drawer.xml看起来如下:

<menu
xmlns:android="http://schemas.android.com/apk/res/android"
>
<group>
    <item
        android:id="@+id/id1"
        android:title="Item 1"/>
    <item
        android:id="@+id/id2"
        android:title="Item 2"/>
    <item
        android:id="@+id/id3"
        android:title="Item 3"/>
    <item
        android:id="@+id/id4"
        android:title="Item 4"/>
</group>
Run Code Online (Sandbox Code Playgroud)

不幸的是,当我这样做时,我点击该抽屉菜单中的项目后没有任何视觉效果.我想要的是所谓的"涟漪效应".我该怎么做?

Yyy*_*Yyy 0

波纹效果可以通过以下方式添加。

将 itemBackground 添​​加到 xml 文件内的 NavigationView 中,并添加以下属性:

应用程序:itemBackground =“@dr​​awable / Ripple_navigation_selector”

另外,在drawable-v21文件夹中,添加ripple_navigation_selector.xml

<?xml version="1.0" encoding="utf-8"?> 
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
        android:color="@color/ripplecolor" >
        <item android:drawable="@color/accentColor" />
        <item
            android:id="@android:id/mask"
            android:drawable="@android:color/white" />
</ripple>
Run Code Online (Sandbox Code Playgroud)