Primary color (sometimes) transparent

I am developing the latest version of the SDK (API 21) and Support Library 21.0.2, and I had problems trying to implement new material design guidelines.

Material Design says that I need to have primary color and my accent color and apply them on top of my application. But sometimes, when I open the application, the primary color becomes transparent in some widgets, it returns to its normal state until I close the application (using the "Back" button) and start it again.

Here is an example of primary color transparency in my toolbar.

enter image description here

I use Teal 500 as the primary color, and as you can see, it is transparent only in android.support.v7.widget.Toolbar . This also happens on my Navigation Drawer and (sometimes, sometimes not) in other random widgets.

This is my toolbar.

 <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/primary" android:minHeight="?attr/actionBarSize" app:theme="@style/ThemeOverlay.AppCompat.ActionBar" > 

I tried with @color/primary and ?attr/colorPrimary without success.

Here is my Theme (I don't know if this is related, but just in case):

 <style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar"> <item name="colorPrimary">@color/primary</item> <item name="colorPrimaryDark">@color/primary_dark</item> <item name="colorAccent">@color/accent</item> <item name="colorAccent">@color/accent</item> <item name="android:textColorPrimary">#fff</item> <item name="windowActionModeOverlay">true</item> <item name="android:textViewStyle">@style/Widget.TextView.White</item> </style> 

This only happens when primary color , accent color excellent. My device is running 4.2.2, and I have not tested it on other devices yet.

Toolbar Actions

 <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <android.support.v7.widget.Toolbar android:id="@+id/my_awesome_toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?attr/colorPrimary" android:minHeight="?attr/actionBarSize" app:theme="@style/ThemeOverlay.AppCompat.ActionBar" /> <FrameLayout android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent" tools:ignore="MergeRootFrame" /> </LinearLayout> <!-- The navigation drawer --> <LinearLayout android:id="@+id/navdrawer" android:layout_width="240dp" android:layout_height="match_parent" android:layout_gravity="start" android:fitsSystemWindows="true" android:orientation="vertical" > <!-- IN THIS IT ALSO HAPPENS --> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingLeft="16dp" android:paddingRight="16dp" android:paddingBottom="16dp" android:orientation="vertical" android:background="@color/primary" > <!-- Some stuff --> </LinearLayout> <ListView android:id="@+id/left_drawer" android:layout_height="match_parent" android:layout_width="match_parent" android:background="@color/black_light" android:divider="@color/grey" android:choiceMode="singleChoice" /> </LinearLayout> </android.support.v4.widget.DrawerLayout> 
+8
android android-5.0-lollipop material-design appcompat android-theme
source share
2 answers

The problem is how the panel background is processed. It is shared between all instances of the toolbar, so if you tend to change the background alpha file on the toolbar, you change the alpha file, which is reused on other screens.

Make sure that you do not control the background properties of the toolbar, instead set a new background color / retrieved each time you want to customize it.

+4
source share

Perhaps these errors in the support library are related to your problem.

https://code.google.com/p/android/issues/detail?id=78289
https://code.google.com/p/android/issues/detail?id=78346

Unfortunately, it is still not fixed in 21.0.2

0
source share

All Articles