How to change the text and icon color of selected menu item on Navigation Drawer programmatically using java : <p>I am a beginner in Android Development. Using android's default Navigation drawer activity I am developing an application. One of the requirements of this app is to change the background colors of layouts (including navigation drawer header color) randomly at run time. </p>

<p>Now everything is going fine except the color of the selected menu item on navigation drawer is still <strong>blue</strong>. like this :</p>

<p><a href="https://i.stack.imgur.com/7hCPk.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/7hCPk.jpg" alt="enter image description here"></a></p>

<p><strong>Now what I want is as the background color of other layouts is pink the selected menu item on the navigation bar should also be pink (I mean the text color and the icon should be pink) like this :</strong></p>

<p><a href="https://i.stack.imgur.com/eCJO1.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/eCJO1.jpg" alt="enter image description here"></a></p>

<p><strong>Can anyone please tell how to achieve it programatically in code as I have to change selected text and icon colors at runtime randomly.</strong></p>

<p>Here's the menu xml file for reference:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;menu xmlns:android="http://schemas.android.com/apk/res/android"&gt;


    &lt;group android:checkableBehavior="single"&gt;
        &lt;item
                android:id="@+id/nav_quiz_all"
                android:icon="@drawable/ic_public_black_24dp"
                android:checked="true"
                android:title="All Countries Quiz"/&gt;
        &lt;item
                android:id="@+id/nav_quiz_bookmarked"
                android:icon="@drawable/ic_favorite_black_24dp"
                android:title="Favorite Quiz"/&gt;
    &lt;/group&gt;


    &lt;item android:title="Communicate"&gt;
        &lt;menu&gt;
            &lt;item
                android:id="@+id/nav_rate"
                android:icon="@drawable/ic_star_black_24dp"
                android:title="Rate this app"/&gt;
            &lt;item
                android:id="@+id/nav_share"
                android:icon="@drawable/ic_share_black_24dp"
                android:title="Share"/&gt;
            &lt;item
                android:id="@+id/nav_feedback"
                android:icon="@drawable/ic_feedback_black_24dp"
                android:title="Feedback"/&gt;
            &lt;item
                android:id="@+id/nav_about"
                android:icon="@drawable/ic_info_black_24dp"
                android:title="About"/&gt;
        &lt;/menu&gt;
    &lt;/item&gt;


    &lt;item
        android:id="@+id/nav_settings"
        android:icon="@drawable/ic_settings_black_24dp"
        android:title="Settings"/&gt;

&lt;/menu&gt;
</code></pre>
