更改汉堡/后退工具栏颜色Android

时间:2017-02-19 22:48:42

标签: android material-design android-toolbar android-navigation-drawer

我想将工具栏中的汉堡包/后轴颜色从colorPrimaryDark更改为白色。

在我的style.xml文件中,我有两个主题:

<!-- 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"

将工具栏样式设置到toolbar.xml中,它也不起作用

enter image description here

enter image description here

奇怪的是,其他主题颜色正确应用。

我哪里错了?

1 个答案:

答案 0 :(得分:1)

解决方法: (但我认为这不是一个优雅的解决方案)

我用这个设置默认箭头图标:

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>
相关问题