Appcombat v7 Toolbar with drawer changing colors

2019-08-03 03:25发布

问题:

I am implementing material design on my app, and I want to be able to change the color of the drawer icon to white, but I couldnt achieve what I am looking for..

This is my themes.xml file:

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <style name="AppTheme" parent="AppTheme.Base" />

    <style name="AppTheme.Base" parent="Theme.AppCompat.Light">
        <item name="colorPrimary">@color/primary</item>
        <item name="colorPrimaryDark">@color/primary_dark</item>
        <item name="android:windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
    </style>

    <style name="HeaderBar" parent="AppTheme.Base">
        <item name="android:textColorPrimary">@android:color/white</item>
        <item name="android:background">@color/primary</item>
        <item name="actionMenuTextColor">@android:color/white</item>
        <item name="android:textColorSecondary">@android:color/white</item>
        <item name="android:actionMenuTextColor">@android:color/white</item>
    </style>

    <style name="ActionBarPopupThemeOverlay" parent="ThemeOverlay.AppCompat.Light">
        <item name="android:background">@android:color/white</item>
        <item name="android:textColor">#000</item>
    </style>

    <style name="ActionBarThemeOverlay" parent="">
        <item name="android:textColorPrimary">#fff</item>
        <item name="colorControlNormal">#fff</item>
        <item name="colorControlHighlight">#3fff</item>
    </style>

</resources>

And this is my toolbar.xml file

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res/jpe.serviguide.commobile"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary"
    app:popupTheme="@style/ActionBarPopupThemeOverlay"
    app:theme="@style/HeaderBar" />

All the colors that I wanted are just fine, but the drawer icon is black instead of white..

I have tried a lot of thing but with no desire result

Thank you so much

回答1:

Finally made it by doing this on my theme.xml file

<style name="AppTheme" parent="Theme.AppCompat.Light">
    ....
    <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>


回答2:

You can do it like this:

    <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:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimaryDark"
        android:minHeight="?attr/actionBarSize"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" - is important part



回答3:

I think your actionbar should have the following parent (ThemeAppCompat.Light):

<style name="HeaderBar" parent="Theme.AppCompat.Light">
    <item name="android:textColorPrimary">@android:color/white</item>
    <item name="android:background">@color/primary</item>
    <item name="actionMenuTextColor">@android:color/white</item>
    <item name="android:textColorSecondary">@android:color/white</item>
    <item name="android:actionMenuTextColor">@android:color/white</item>
</style>


回答4:

Hi neteot always when I work with costume bars I create a custom layout as a bar, then in my case the bars button/burguer button is a ImageButton... Then you need to change color of the icon

If you want to create a perfect custom bar, u can see my last post:

https://stackoverflow.com/questions/27417923/android-add-custom-buttons-on-action-bar/27418306#27418306

Good luck and I wait than I helps you!!

PD: If you need more info or any doubt, advice me!