When you click a menu item in my navigation drawer, it becomes slightly darker and remains that way until another item is clicked. I'm trying to keep it the same colour no matter what state it's in.
Is it some kind of overlay? I've think I've covered all possible states in drawer_items.xml.
How do I prevent this behaviour?
activity_main.xml
<android.support.design.widget.NavigationView
.
.
android:background="@drawable/drawer_items"
.
app:menu="@menu/activity_main_drawer" />
drawer_items.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/grey" android:state_activated="true" />
<item android:drawable="@color/grey" android:state_selected="true" />
<item android:drawable="@color/grey" android:state_focused="true" />
<item android:drawable="@color/grey" android:state_pressed="true" />
<item android:drawable="@color/grey" android:state_checked="true" />
<item android:drawable="@color/grey" />
</selector>
activity_main_drawer.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single"
android:id="@+id/arbitrary_id_1">
<item
android:id="@+id/nav_refresh"
android:icon="@drawable/ic_refresh_24dp"
android:title="Try Again/Refresh" />
</group>
<group android:checkableBehavior="single"
android:id="@+id/arbitrary_id_2">
<item
android:id="@+id/nav_back"
android:icon="@drawable/ic_fast_rewind_24dp"
android:title="Go Back" />
</group>
<group android:checkableBehavior="single"
android:id="@+id/arbitrary_id_3">
<item
android:id="@+id/nav_3" />
</group>
</menu>
You can highlight a menu by adding a different background color, text color etc to the particular menu item using custom CSS. To apply custom CSS you need to add CSS class for the menu.
Add a navigation drawerThe drawer appears when the user touches the drawer icon in the app bar or when the user swipes a finger from the left edge of the screen. Figure 3. An open drawer displaying a navigation menu. The drawer icon is displayed on all top-level destinations that use a DrawerLayout .
Maybe you can use something like this,
to prevent item from changing its color when clicked, you can try to change in activity_main_drawer.xml
:
<group android:checkableBehavior="single">
to
<group android:checkableBehavior="none">
Or you can do this way:
<group android:checkableBehavior="single">
...
<item
android:id="@+id/item_one"
android:icon="@drawable/ic_item_one"
android:title="Item One"/>
...
</group>
To:
<item>
<menu>
...
<item
android:id="@+id/item_one"
android:icon="@drawable/ic_item_one"
android:title="Item One"/>
...
</menu>
</item>
Read more at Menus
So the NavigationView
is highlighted based on the colorControlHighlight
property. You could create a theme for your drawer and make it transparent:
<style name="Drawer" parent="Theme.AppCompat.Light">
<item name="colorControlHighlight">#0000</item>
</style>
<android.support.design.widget.NavigationView
...
android:theme="@style/Drawer" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With