Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DrawerLayout with NavigationView - not showing ripple effect on click

I have a problem with obtaining on-click effect visible at my drawer.

I have activity xml layout as follows:

    <?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>

As you can see I put NavigationView into my DrawerLayout and then populate NavigationView using menu xml file.

My activity_main_drawer.xml looks as follows:

<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>

Unfortunately, when I do it that way I don't have any visual effect after clicking on item in that drawer menu. What I would like is to have so called "ripple effect". How can I do it?

like image 736
michalsol Avatar asked Jun 07 '17 14:06

michalsol


2 Answers

I have also faced this problem

Please Remove this attributes:

clickable=true

focusableOnTouch=true

then apply ripple effect XML

<ripple xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:color="@android:color/transparent"
tools:targetApi="lollipop"> <!-- ripple color -->

<item android:drawable="@android:color/transparent" /> <!-- normal color -->

I Hope it will help you

like image 131
Sejal Baraiya Avatar answered Nov 17 '22 17:11

Sejal Baraiya


You can use set the attribute itemBackground with ?android:attr/selectableItemBackground to get the ripple effect for your NavigationView items

<android.support.design.widget.NavigationView
     /* ... other attributes... */
     app:itemBackground="?android:attr/selectableItemBackground"/>
like image 45
Anna Duong Avatar answered Nov 17 '22 16:11

Anna Duong