1

I am trying to change the text color of the Activity Main Drawer but I cant find where to change it. I want to change it to a lighter color (white)

enter image description here

This is whats inside of my activity_main_drawer.xml

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

<group android:checkableBehavior="single">
    <item android:id="@+id/nav_city1" android:icon="@android:drawable/ic_menu_mapmode"
        android:title="Label1" />
    <item android:id="@+id/nav_city2" android:icon="@android:drawable/ic_menu_compass"
        android:title="Label2" />
    <item android:id="@+id/nav_city3" android:icon="@android:drawable/ic_menu_myplaces"
        android:title="Label3" />
    <item android:id="@+id/nav_city4" android:icon="@android:drawable/ic_input_get"
        android:title="Label4" />
</group>

<item android:title="Account">
    <menu>
        <item android:id="@+id/nav_profile" android:icon="@android:drawable/ic_menu_edit"
            android:title="Profile" />
        <item android:id="@+id/nav_settings" android:icon="@android:drawable/ic_menu_manage"
            android:title="Settings" />
    </menu>
</item>

I tried inserting android:textColor everywhere but its not working.

<menu xmlns:android="http://schemas.android.com/apk/res/android"
android:textColor="#FFFFFF">

<group android:checkableBehavior="single" android:textColor="#FFFFFF">
    <item android:id="@+id/nav_cities" android:icon="@android:drawable/ic_menu_mapmode"
        android:title="Cities" android:textColor="#FFFFFF"/>
TwoThumbSticks
  • 1,086
  • 3
  • 23
  • 38

4 Answers4

3
  • You need to initialize the colors you want to use using the
    ColorStateList object.

  • After setting up the colors for each state you set the navitaionView itemTextColor (navigation.setItemTextColor(yourCustomColorStateList);

This is where I got the answer
Here is another related Stackoverflow questions
Official Android documentation of all the available kind of state

example: Use this inside your onCreate method of your main class

NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    /**
     * start of code configuration for color of text of your Navigation Drawer / Menu based on state
     */
    int[][] state = new int[][] {
            new int[] {-android.R.attr.state_enabled}, // disabled
            new int[] {android.R.attr.state_enabled}, // enabled
            new int[] {-android.R.attr.state_checked}, // unchecked
            new int[] { android.R.attr.state_pressed}  // pressed

    };

    int[] color = new int[] {
            Color.WHITE,
            Color.WHITE,
            Color.WHITE,
            Color.WHITE
    };

    ColorStateList colorStateList1 = new ColorStateList(state, color);


    // FOR NAVIGATION VIEW ITEM ICON COLOR
    int[][] states = new int[][] {
            new int[] {-android.R.attr.state_enabled}, // disabled
            new int[] {android.R.attr.state_enabled}, // enabled
            new int[] {-android.R.attr.state_checked}, // unchecked
            new int[] { android.R.attr.state_pressed}  // pressed

    };

    int[] colors = new int[] {
            Color.WHITE,
            Color.WHITE,
            Color.WHITE,
            Color.WHITE
    };
    ColorStateList colorStateList2 = new ColorStateList(states, colors);
    navigationView.setItemTextColor(colorStateList1);
    navigationView.setItemIconTintList(colorStateList2);
    /**
     * end of code configuration for color of text of your Navigation Drawer / Menu based on state
     */
Community
  • 1
  • 1
royjavelosa
  • 2,048
  • 6
  • 30
  • 46
2

You can achieve same through xml by just using app:itemTextColor inside your NavigationView:

 <android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_height="match_parent"
    android:layout_width="240dp"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    android:background="@color/colorWhite"
    app:headerLayout="@layout/drawer_header"
    app:menu="@menu/drawer_view"
    app:itemTextColor="@color/colorWhite">

Adding the above single line to your xml should work in your case.
Hope it helps!

PunitD
  • 2,293
  • 1
  • 20
  • 29
0

It seems your using the new Android Support Design Library. I haven't used it. I feel you need to have a some Header Layout which consists of the TextView as shown in the above screenshot. And later in the Java code you can access the Header Layout and using findViewById() to get the TextViews.

Let me know if it works.

Akshay Chordiya
  • 4,761
  • 3
  • 40
  • 52
0

You can using app:itemTextColor inside your NavigationView

<?xml version="1.0" encoding="utf-8"?>
<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:background="#FFDFE3"
    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"
        <!-- here you can change color of items like this. -->
        app:itemTextColor="@color/colorHeaderBackground"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer" />

</android.support.v4.widget.DrawerLayout>
harun ugur
  • 1,718
  • 18
  • 18