android appcompat v22 2 Global theme overrides toolbar theme for burger icon

706 views Asked by At

I'm using the support library AppCompat v7 22.2. My app uses a light theme that I've set up as follows

<style name="Theme.SM3Theme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/s3m_primary</item>
    <item name="colorPrimaryDark">@color/s3m_primary_dark</item>
    <item name="colorAccent">@color/s3m_accent</item>
</style>

In my manifest I have

<application
    android:allowBackup="false"
    android:icon="@drawable/icon"
    android:theme="@style/Theme.SM3Theme"

I want my Toolbar to be themed dark so I get light colours on a dark background, like so

<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/sm3_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/s3m_primary"
android:minHeight="?attr/actionBarSize"
android:theme="@style/Theme.AppCompat"
app:popupTheme="@style/ThemeOverlay.AppCompat"
android:gravity="center" >

And it almost works. I don't have the 10 reputation needed to post images but the burger icon for the DrawerLayout is always black in line with the Light theme of the global theme. The back arrow and the title text are light/white which is consistent with the theme specified in the Toolbar.

I've can't seem to get that to change. Worked fine with version 21 but then I didn't have to use Theme.AppCompat.Light.NoActionBar until I got the "IllegalArgumentException: AppCompat does not support the current theme features" errors.

Anybody know how to get this to work? Happening on both Lollipop and Jellybean 4.3

3

There are 3 answers

1
Ankur On BEST ANSWER

Add following in your app theme Theme.SM3Theme

<item name="drawerArrowStyle">@style/Widget.SM3Theme.DrawerArrowToggle</item>

Create style Widget.SM3Theme.DrawerArrowToggle as follows:

<style name="Widget.SM3Theme.DrawerArrowToggle" parent="Widget.AppCompat.DrawerArrowToggle">
    <item name="color">@android:color/white</item>
</style>
5
tyczj On

you are using the wrong themes, you need to use these in your toolbar

app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
5
natario On

You should be able to alter that color using the colorControlNormal attribute. Try defining a new style:

<style name="ToolbarTheme" parent="Theme.AppCompat">
    <item name="colorControlNormal">@color/white</item>
</style>

and use android:theme="@style/ToolbarTheme" over the Toolbar.

Looks like AppCompat's ThemeOverlays set the colorControlNormal attribute to be android:textColorPrimary, which is definitely not what we are looking for, because it will stick to the main theme you have set - a light one, in your case.