Widget not tinted on Lollipop

I am using appcompat v21.0.3 for my application. I did everything as it is written here: android-developers.blogspot.com/2014/10/appcompat-v21-material-design-for-pre.html

But on Lollipop (and, of course, on older devices) some widgets are not painted with the color of my accent. For example:

  • SwitchCompat tinted: switchcompat

  • ListPreference is NOT tinted enter image description here

  • ProgressDialog is NOT tinted enter image description here

Here is my code:

build.gradle

... compile 'com.android.support:appcompat-v7:21.0.+' ... 

AndroidManifest.xml

 <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/CET" android:hardwareAccelerated="true" tools:replace="label"> 

themes.xml

 <resources> <style name="CET" parent="Theme.AppCompat.Light.NoActionBar"> <item name="windowActionBar">false</item> <item name="colorPrimary">@color/primary</item> <item name="colorPrimaryDark">@color/primary_dark</item> <item name="colorAccent">@color/accent</item> </style> </resources> 

colors.xml

 <resources> <!-- App branding color --> <color name="primary">#a32b30</color> <!-- Darker variant for status bar and contextual app bars --> <color name="primary_dark">#000000</color> <!-- Theme UI constrols like checkboxes and text fields --> <color name="accent">#a32b30</color> </resources> 

Does anyone have any ideas?

UPDATE: as of June 2015 still not working, but I ended up using https://github.com/afollestad/material-dialogs . Works very well for dialogs, including ListPreferences.

+8
android android-5.0-lollipop android-widget appcompat
source share
6 answers

Follow the guide below

Unless otherwise specified, all of the shades below apply to both Lollipop and pre-Lollipop using AppCompat v21. To use the support version of these attributes, remove the android namespace. For example, "android: colorControlNormal" becomes "colorControlNormal". These attributes will apply to their corresponding attributes in the android namespace for devices running Lollipop. Any exceptions to this will be noted by including the prefix "android:".

 All Clickable Views: ----------- * ripple effect (Lollipop only) -- "colorControlHighlight" Status Bar: ------------ * background (Lollipop only) - "colorPrimaryDark" Navigation Bar: ---------------- * background (Lollipop only) - "android:navigationBarColor" EditText: ---------- * underline (unfocused) -- "colorControlNormal" * underline overlay (focus) -- "colorAccent" * cursor -- "colorAccent" * text color -- "android:textColorPrimary" CheckBox: ---------- * box unchecked -- "colorControlNormal" * box checked -- "colorAccent" RadioButton: ------------- * unselected -- "colorControlNormal" * selected -- "colorAccent" * ripple effect (Lollipop only) -- "colorControlHighlight" SwitchCompat: ------------- * thumb switch off -- "colorSwitchThumbNormal" * thumb switch on -- "colorAccent" * track overlay (when switched on) -- "colorAccent" Spinner: --------- * indicator (not pressed) -- "colorControlNormal" * indicator (pressed) -- "colorAccent" * selected entry text color (Lollipop only) -- "android:textColorPrimary" ActionBar: ----------- * background -- "colorPrimary" * title color -- "android:textColorPrimary" * overflow icon -- "android:textColorPrimary" * up button -- "android:textColorPrimary" * action icons -- "android:textColorPrimary" † * overflow menu background -- "android:colorBackground" * overflow text color -- "android:textColorPrimary" Toolbar (Theme Overlay should be used): ---------------------------------------- * background -- must be set manually in XML. Can do (android:background="?attr/colorPrimary") * overflow icon -- "android:textColorPrimary" * navigation icon -- "android:textColorPrimary" † * action icons -- "android:textColorPrimary" † * overflow menu background -- "android:colorBackground" * overflow text color -- "android:textColorPrimary" 

PS tinting by default only works with action icons of the white icon (see TintManager source code). For example, the back arrow icon "abc_ic_ab_back_mtrl_am_alpha" tinted, but copying this exact file and renaming it will cause the icon to not be tinted when shooting a random image and renaming it to "abc_ic_ab_back_mtrl_am_alpha" will tint it. Toning can be done in XML in Lollipop by creating a <bitmap> xml file in drawable and applying the attribute "android:tint" . This icon can be used in both Lollipop and pre-Lollipop, but it will only be tinted in Lollipop. Toning action icons can also be done programmatically using ColorFilter .

A source

+28
source share

Usually you should use your own progress bar instead of a dialog, and then you can make a tinted version that works on both L and pre-L, for example:

 public class TintedProgressBar extends ProgressBar { public TintedProgressBar(Context context) { super(context); init(); } public TintedProgressBar(Context context, AttributeSet attrs) { super(context, attrs); init(); } public TintedProgressBar(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(); } public void init() { getIndeterminateDrawable().setColorFilter(getResources().getColor(R.color.primary), PorterDuff.Mode.SRC_IN); getProgressDrawable().setColorFilter(getResources().getColor(R.color.primary), PorterDuff.Mode.SRC_IN); } } 

If you really want to change the color in the dialog box, you can find the nested progress bar, possibly in dialog.findViewById(android.R.id.progess)

+12
source share

To change the color of the Progress Dial drawable dialog box, I used the following workaround: I created the basic style of the AppCompat alert dialog box

  <style name="CustomAppCompatAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert"> <item name="colorAccent">@color/defaultColor</item> <item name="android:indeterminateTint">?attr/colorAccent</item> <item name="android:indeterminateTintMode">src_in</item> </style> 

And then apply this theme to the progress dialog box:

 mProgressDialog = new ProgressDialog(this, R.style.CustomAppCompatAlertDialogStyle); 
+5
source share

It answers only part of your question, but the runtime style from the appcompat library does not raise the color of emphasis on candy, even outside of ProgressDialog .

You need to configure it yourself, for example, using this style:

 <style name="TintedProgressBar" parent="Widget.AppCompat.ProgressBar"> <item name="android:indeterminate">true</item> <item name="android:indeterminateTint">?attr/colorAccent</item> <item name="android:indeterminateTintMode">src_in</item> </style> 

which can then be applied to a ProgressBar or ContentLoadingProgressBar . (note that the parent element on which the progress bar is inflated must explicitly apply the theme that defines the colorAccent attribute, otherwise use a direct color resource)

If you want to integrate the progress bar in the dialog box , since I don’t think that ProgressDialog supports setting your progress bar outside of the type and drawable, you may need to set up AlertDialog using the progress bar using the theme above, or just go with the custom dialog I suppose you can refer to this answer to apply the above progress bar attributes in a dialog box.

+3
source share

Try the colorControlActivated attribute:

themes.xml

 <style name="CET" parent="Theme.AppCompat.Light.NoActionBar"> <item name="windowActionBar">false</item> <item name="colorPrimary">@color/primary</item> <item name="colorPrimaryDark">@color/primary_dark</item> <item name="colorAccent">@color/accent</item> <item name="colorControlActivated">#a32b30</item> </style> 

+1
source share

As far as I know, nothing in the dialog will automatically be painted in Lollipop (for now). Checkout material-dialogs , the library for this is automatically for you (but it only supports API 14 +).

Answers to questions on a similar question: Android v21 Theme.Appcompat color accent is ignored, no indentation in dialogs

0
source share

All Articles