更改汉堡包/背箭筒工具栏颜色Android

问题描述:

我想将colorBrimaryDark中我的汉堡包/背箭的颜色从colorPrimaryDark更改为白色。更改汉堡包/背箭筒工具栏颜色Android

在我style.xml文件我有2个主题:

<!-- Base application theme. --> 
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorPrimary</item> 
    <item name="colorButtonNormal">@color/white</item> 
    <item name="android:windowTranslucentStatus">true</item> 
</style> 


<!-- Toolbar theme. --> 
<style name="toolbar" parent="AppTheme"> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/white</item> 
    <item name="colorControlNormal">@color/white</item> 
    <item name="windowActionBar">false</item> 
    <item name="windowNoTitle">true</item> 
    <item name="android:textColorPrimary">@color/white</item> 
    <item name="android:textColor">@color/black</item> 
    <item name="android:textColorSecondary">@android:color/white</item> 
</style> 

,这是我的工具栏:

<android.support.v7.widget.Toolbar 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/toolbar" 
    android:fitsSystemWindows="true" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/colorPrimary" 
    android:elevation="4dp" 
    android:theme="@style/toolbar"> 
</android.support.v7.widget.Toolbar> 

我试着用多种方法和工作原理是移动<item name="android:textColorSecondary">@android:color/white</item>从只有一个基本应用程序主题的工具栏主题

这对我来说并不好,因为在基本主题中将textColorSecondary设置为白色也会改变其他组件的颜色。 我想只为我的工具栏设置它。然而,尽管我有<item name="android:textColorSecondary">@android:color/white</item>它甚至不工作,并且使用"android:theme="@style/toolbar"

enter image description here

enter image description here

奇怪的是,其他的主题颜色运用得当,设置我的工具栏风格融入toolbar.xml。

我在哪里错了?

+0

您是否试过[this](http://*.com/questions/31870132/how-to-change-color-of-hamburger-icon-in-material-design-navigation-drawer)? – azizbekian

+0

是的,但它只改变了汉堡包图标的颜色,不是两种,为什么? – BitRulez

解决方法: (但我认为它不是一个完美的解决方案)

我设置这种默认的箭头图标:

toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_material); 

,改变汉堡包颜色与此:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
     <item name="colorPrimary">@color/colorPrimary</item> 
     <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
     <item name="colorAccent">@color/colorPrimary</item> 
     <item name="colorButtonNormal">@color/white</item> 
     <item name="drawerArrowStyle">@style/DrawerArrowStyle</item> 
</style> 

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