I'm having an issue where changing the background drawable of the support ActionBar changes the color of most of the bar but leaves the old color around the text and icons. I've tried changing the color of the support ActionBar and the ToolBar that I used to make it. I've tried many different ways of invalidating the UI elements. I've tired setting the color and text is different orders. I've tried hiding and showing the text. I just can't make it turn to one solid color.
Here's what I have for my ActionBar style:
<style name="LocationBar" parent="ThemeOverlay.AppCompat.ActionBar">
<item name="android:textColorPrimary">@color/text_color_primary_inverse</item>
<item name="android:textColorSecondary">@color/text_color_primary_inverse</item>
<item name="android:background">@color/weather_cool</item>
</style>
This is how I'm adding it to my activity:
<android.support.v7.widget.Toolbar
android:id="@+id/location_bar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="@style/LocationBar"/>
This in the Java code I set it as the supportActionBar:
_locationBar = (Toolbar)findViewById(R.id.location_bar);
setSupportActionBar(_locationBar);
Then after I fetch the weather I try to adjust the color like this:
ColorDrawable warmDrawable = new ColorDrawable(ContextCompat.getColor(this, R.color.weather_warm));
getSupportActionBar().setBackgroundDrawable(warmDrawable);
Which results in what you see in the picture. Most of the bar changes color but not all of it.
...changing the background drawable of the support ActionBar changes the color of most of the bar but leaves the old color around the text and icons...
The reason this is happening is because you're using android:theme
instead of style
. theme
gets applied to every child in your Toolbar
, in this case including the TextView
title background and your settings button background. style
is meant to be used at the view level and will only be applied to your Toolbar
background.
Before
<android.support.v7.widget.Toolbar
...
android:theme="@style/LocationBar" />
After
<android.support.v7.widget.Toolbar
...
style="@style/LocationBar" />