Sanyasirao Mopada
Sanyasirao Mopada

Reputation: 953

Navigation view item different icon colors for different items

I am using navigation view , I want to put different colored icons for different items for unselected items and white colored icon for selected item.

I am using menu for items, I have seen below example for could not apply for my problem

Different select colors for different list view items

Thank you

Upvotes: 0

Views: 749

Answers (2)

iSrinivasan27
iSrinivasan27

Reputation: 1426

You can add different colored icon into drawable directory.

Remove navigation default color on icons by programmatically

mNavigationView.setItemIconTintList(null);

By XML

<android.support.design.widget.NavigationView
...
app:itemIconTint="null" 
... />

To set white Color on selected item

Create drawable resource file under drawable directory with Selector and add below code.

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true" android:color="@android:color/white"/>
    <item android:state_checked="false" android:color="Your color" />
</selector>

Upvotes: 1

linjiang
linjiang

Reputation: 116

1.put your icons into drawable-xx file. 2.new one android-xml-file named 'selector_btn',android choose 'selector' type for it. 3.code it like this:

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

4.in your menu layout, set background for your button.

Upvotes: 0

Related Questions