Navigation view: I want on menu click, menu item not to change background

Viewed 107

I have a problem with navigation view, on menu item click I want background not to change color.

Here is my drawer layout

    <android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start"
    android:orientation="vertical">


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

    <android.support.design.widget.NavigationView
        android:background="@color/blue_dark"
        app:itemTextAppearance="@style/NavDrawerTextStyle"
        app:itemBackground="@drawable/nav_menu_background_selector"
        app:itemTextColor="@color/nav_menu_color_change"
        android:theme="@style/NavigationDrawerStyle"
        android:id="@+id/nav_view"
        android:paddingLeft="47px"
        android:layout_width="match_parent"
        android:layout_height="600dp"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer" >

        <View
            android:layout_gravity="right"
            android:background="@color/color_lite_green"
            android:layout_width="2dp"
            android:layout_height="match_parent"></View>

    </android.support.design.widget.NavigationView>


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

I have tried with and without selector. Here is my selector

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@color/blue_dark" />
    <item android:state_pressed="false" android:drawable="@color/blue_dark" />
</selector>

When I make selector like this with the same background as menu items background, on click it appears some kind of shadow. When I don't use the selector, the same thing is happening on menu item click. I just want on menu click not to change the background. How can I achieve this? I have tried solutions for similar problems, and nothing has worked so far.

Thanks

1 Answers

I faced the same issue, 2 solutions, in 'onNavigationItemSelected(MenuItem item)' add for each item 'item.setCheckable(true);' , or in the menu items layout add 'android:checkable="true"'.

Related