Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't change navigation drawer icon color in android

OK, I know this is a trivial issue but for some reason it isn't working for me. I have done a lot of things suggested in other answers but in vain. My drawable folder has white color icons. I even tried to change it from styles.xml but that doesn't work either. I am testing it on my Lollipop device. Any help will be appreciated. Thanks in advance.

This is a portion of my manifest file.

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_drawer"
        android:label="@string/app_name" >
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version"
            tools:replace="android:value" />

        <activity
            android:name=".Activity_Splash"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
                android:name=".Activity_test"
                android:launchMode="singleInstance"
                android:theme="@style/AppTheme.Base"
                android:windowSoftInputMode="stateHidden" />

And finally this is my style.xml. Similar is for v-21.

<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowContentTransitions">true</item>
        <item name="android:windowAllowEnterTransitionOverlap">true</item>
        <item name="android:windowAllowReturnTransitionOverlap">true</item>
        <item name="android:actionMenuTextColor">#fff</item>
        <item name="colorPrimary">@color/ColorPrimary</item>
        <item name="colorPrimaryDark">@color/ColorPrimaryDark</item>
        <item name="drawerArrowStyle">@style/MyDrawerArrowToggle</item>
        <item name="windowActionBar">false</item>
        <item name="colorAccent">#fff</item>
        <item name="android:windowSharedElementEnterTransition">@android:transition/move</item>
        <item name="android:windowSharedElementExitTransition">@android:transition/move</item>
</style>
like image 952
varunkr Avatar asked Jul 19 '15 21:07

varunkr


People also ask

How do I customize my navigation drawer?

Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. Step 3 − Add the following code to res/layout/nav_header_main.

How to create a custom navigation drawer in Android</strong>?

How to create a custom navigation drawer in Android? This example demonstrate about How to resize Image in Android App. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.xml.

How to change the color of the navigation drawers icon?

You can achieve by writing app:itemIconTint but if you write this, the navigation drawers icon color will also be changed.

How do I view the navigation drawer?

The user can view the navigation drawer when the user swipes a finger from the left edge of the activity. They can also find it from the home activity by tapping the app icon in the action bar. The drawer icon is displayed on all top-level destinations that use a DrawerLayout.

How to add navigation header in Android Studio?

Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Add the following code to res/layout/nav_header_main.xml.


2 Answers

You should use ThemeOverlay.AppCompat.Dark.ActionBar as your toolbar style. It sets colorControlNormal to android:textColorPrimary, which is white for dark themes. And it doesn't change other attrs from main style.

<android.support.v7.widget.Toolbar xmlns:app="http://schemas.android.com/apk/res-auto" >
    ... 
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
</android.support.v7.widget.Toolbar>

Also remove drawerArrowStyle from your main style, it's not needed.

like image 187
srka Avatar answered Oct 05 '22 13:10

srka


If you are using the Design support library, you can modify the icon colours using the app:itemIconTint property:

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="left"
    android:fitsSystemWindows="true"
    android:theme="@style/AppTheme"
    app:headerLayout="@layout/nav_header_main"
    app:itemIconTint="#f00"
    app:itemTextColor="#0f0"
    app:menu="@menu/nav_drawer" />

As a bonus, above also shows how to change the colour of the text with app:itemTextColor.

like image 39
Richard Le Mesurier Avatar answered Oct 05 '22 14:10

Richard Le Mesurier