Parth Anjaria
Parth Anjaria

Reputation: 3971

Change color of default navigation menu

I have seen this questions at many places but everywhere they have used a custom listview inside the navigation menu.

My code for navigationview is like this :

<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"
        app:headerLayout="@layout/nav_header_insta_drawer"
        app:menu="@menu/activity_insta_drawer_drawer" />

where my @menu/activity_insta_drawer_drawer is like this :

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <group android:checkableBehavior="single">
        <item
            android:id="@+id/nav_applnform"
            android:icon="@drawable/application_form"
            android:title="Application Form"
            android:checkable="true"

            />
        <item
            android:id="@+id/nav_penddocs"
            android:icon="@drawable/pending_doc"
            android:title="Pending Documents"

            />
        <item
            android:id="@+id/nav_viewdocs"
            android:icon="@drawable/view_doc"
            android:title="View Documents" />
        <item
            android:id="@+id/nav_payfee"
            android:icon="@drawable/pay_free"
            android:title="Pay Fee" />
         <item
                android:id="@+id/nav_refereedetail"
                android:icon="@drawable/refree_detail"
                android:title="Referee Details" />
         <item
                android:id="@+id/nav_informcorner"
                android:icon="@drawable/information"
                android:title="Information Corner" />
        <item
            android:id="@+id/nav_changepass"
            android:icon="@drawable/change_pass"
            android:title="Change Password" />
        <item
            android:id="@+id/nav_postquery"
            android:icon="@drawable/ic_menu_send"
            android:title="Post Query" />
      </group>
</menu>

code for navigationview :

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

How to i change the selected item of the menu?

Upvotes: 1

Views: 466

Answers (2)

pRaNaY
pRaNaY

Reputation: 25312

Try to change your NavigationView like below with adding app:itemTextColor="@drawable/nav_draw_selector" to change navigation menu text color:

<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"
    app:itemTextColor="@drawable/nav_draw_selector"
    app:headerLayout="@layout/nav_header_insta_drawer"
    app:menu="@menu/activity_insta_drawer_drawer" />

nav_header_insta_drawer.xml

 <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="#4281ca" android:state_checked="true" />     <!-- This is the default text color -->
    <item android:color="#DEDEDE" />
</selector>

Upvotes: 1

Parth Anjaria
Parth Anjaria

Reputation: 3971

Finally after trying out everything i got the answer You must change the colorAccent in the colors file to which ever color you want :

  <color name="colorAccent">whichever color required</color>

This solution worked for me

Upvotes: 1

Related Questions