Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change Item text color of NavigationView

How can i change NavigationView menu item text color.My menu.xml file is, i also write

app:itemIconTint="@color/white" app:itemTextColor="@color/white" in my layout but it will not work

<?xml version="1.0" encoding="utf-8"?>

<item
    android:checked="false"
    android:title="@string/popular">
    <menu>
        <item
            android:id="@+id/tag1"
            android:checked="false"
            android:icon="@drawable/bird"
            android:title="@string/tag1" />

        <item
            android:id="@+id/tag2"
            android:checked="false"
            android:icon="@drawable/rabbit"
            android:title="@string/tag2" />

        <item
            android:id="@+id/tag3"
            android:checked="false"
            android:icon="@drawable/bird"
            android:title="@string/tag3" />

        <item
            android:id="@+id/tag4"
            android:checked="false"
            android:icon="@drawable/rabbit"
            android:title="@string/tag4" />


        <item
            android:id="@+id/tag5"
            android:checked="false"
            android:icon="@drawable/bird"
            android:title="@string/tag5" />
        <item
            android:id="@+id/setting"
            android:checked="false"
            android:icon="@drawable/setting"
            android:title="@string/setting" />
        <item
            android:id="@+id/rate"
            android:checked="false"
            android:icon="@drawable/rating"
            android:title="@string/rate" />
    </menu>
</item>

Here is my NavigationView in my app as you can see there is no any effects if itemTextColor

my NavigationView like..

 <android.support.design.widget.NavigationView
    android:id="@+id/navigation_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="@color/theme_primary"
    app:headerLayout="@layout/layout_drawer_header"
    app:itemIconTint="@color/white"
    app:itemTextColor="@color/white"
    app:menu="@menu/menu_main" />
like image 577
Gaurav Mandlik Avatar asked Jul 12 '16 09:07

Gaurav Mandlik


2 Answers

thanks for the response, i just search little and i found the answer there is no any style changes, i just change in JAVA file like and it's done.

NavigationView navigation_view = (NavigationView) findViewById(R.id.navigation_view);
    navigation_view.setItemTextColor(ColorStateList.valueOf(Color.BLACK));
    navigation_view.setItemIconTintList(null);
like image 118
Gaurav Mandlik Avatar answered Nov 11 '22 18:11

Gaurav Mandlik


NavigationView uses the color of Widget.Design.NavigationView theme. You can override that theme like following.

Create your own style which overridesWidget.Design.NavigationView in your style.xml:

<style name="NavigationStyle" parent="Widget.Design.NavigationView">
    <item name="android:textColorPrimary">@color/white</item>
    <item name="android:textColorSecondary">@color/white</item>
</style>

Use that theme in your layout xml file:

<android.support.design.widget.NavigationView
        ...
        android:theme="@style/NavigationStyle"
        ... />
like image 1
nshmura Avatar answered Nov 11 '22 20:11

nshmura