Wrong toolbar background (Android)
I am using toolbar in my application. It should look like this:
But sometimes the background of the toolbar is wrong! I have no idea why this is happening ...
Here's my layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/toolbar"/>
......
Here's my dashboard:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/id_toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"/>
Help! Any ideas?
devices:
Communication 5 (4.4.4)
huawei honor 6 (4.4.2)
source to share
Check your style resource files if you have defined colorPrimary
.
It is very important to check if your definition contains something like this <item name="android:colorPrimary">@color/actionbar_solid_background</item>
. This will not work on previous versions of Android (<21) as it targets the main OS resource. If this case removes android:
to target the resource used by the support library.
Your style should be something like this.
<style name="MyTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/actionbar_solid_background</item>
<item name="colorPrimaryDark">@color/actionbar_solid_background</item>
</style>
source to share