Navigation drawer icon change color

2015-08-01 android

I want to change the color of navigation drawer icon(3 vertical bars) from white to grey. How do i do this in the simplest way?

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="@color/grey"
local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
local:popupTheme="@style/ThemeOverlay.AppCompat.Light" >

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Toolbar Title"
    android:id="@+id/toolbar_title"
    android:textColor="#010101" />
<!--android:layout_gravity="center"-->



</android.support.v7.widget.Toolbar>

Answers

You can change the icon itself programmatically, using something like this:

toolbar.setNavigationIcon(R.drawable.new_icon);

Change you toolbar's theme

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="@color/grey"
local:theme="@style/CustomTheme"
local:popupTheme="@style/ThemeOverlay.AppCompat.Light" >

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Toolbar Title"
    android:id="@+id/toolbar_title"
    android:textColor="#010101" />
<!--android:layout_gravity="center"-->



</android.support.v7.widget.Toolbar>

And in your styles.xml

Create new style like this.

<style name="CustomTheme" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
    <item name="android:textColorPrimary">#COLOR_CODE_FOR_YOUR_TEXT</item>
    <item name="android:textColorSecondary">#COLOR_CODE_FOR_YOUR_TOOLBAR_ICON</item>
</style>

Get the drawable

Drawable icMenu = ContextCompat.getDrawable(this, R.drawable.ic_hamburguer);

Tint the drawable

icMenu.setColorFilter(getResources().getColor(android.R.color.darker_gray), PorterDuff.Mode.SRC_ATOP);

Use it with the actionBar

actionBar.setHomeAsUpIndicator(icMenu);

actionBar.setDisplayHomeAsUpEnabled(true);

Or the toolbar

toolbar.setNavigationIcon(icMenu);

Related