简体   繁体   中英

Changing the hamburger icon color in navigation drawer

Hamburger icon color of navigation drawer is not changing. Its black by default. I want to change it to @color/gold. its working for API below 21. Please help me.

here is the style i am using.

<style name="AppTheme.NoActionBar" >
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="windowActionBar">false</item>
    <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
    <item name="windowNoTitle">true</item>
    <item name="android:textColorPrimary">@color/gold</item>
    <item name="actionMenuTextColor">@color/gold</item>
    <item name="android:actionMenuTextColor">@color/gold</item>
    <item name="colorControlNormal">@color/gold</item>
</style>

<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
    <item name="spinBars">true</item>
    <item name="color">@color/gold</item>

</style>

Answer thanks to Iron man

changed the entire theme

  <style name="MyMaterialTheme" parent="MyMaterialTheme.Base">

</style>

<style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar" >
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:textColorSecondary">@color/booking</item>
    <item name="windowActionBar">false</item>
    <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
    <item name="windowNoTitle">true</item>
    <item name="android:textColorPrimary">@color/booking</item>
    <item name="actionMenuTextColor">@color/booking</item>
    <item name="android:actionMenuTextColor">@color/booking</item>
    <item name="colorControlNormal">@color/booking</item>
</style>

<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
    <item name="spinBars">true</item>
    <item name="color">@color/booking</item>

</style>

Create style in your styles.xml and put the following code

<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
    <item name="color">@android:color/white</item>
</style>

And then add the theme like so:

< item name="drawerArrowStyle">@style/DrawerArrowStyle</item>

you can give tint color of your icon below way

Drawable drawable = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_menu, null);
drawable = DrawableCompat.wrap(drawable);
DrawableCompat.setTint(drawable, Color.GOLD);
actionBar.setHomeAsUpIndicator(drawable);

Pretty simple, programmatically you just need to add below line of code...

actionBarDrawerToggle.getDrawerArrowDrawable()
                     .setColor(getResources().getColor(R.color.white));

Done!

write this code into your values/style

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:textColorPrimary">@color/white</item>
    <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>

</style>

<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">@android:color/white</item>
</style>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM