Android v21 Theme.Appcompat color accent is ignored, no additions to the dialog

I am using ActionBarActivity from the Android 5 SDK, and here is my theme.xml for v21

<style name="AppTheme_Light" parent="Theme.AppCompat.Light.DarkActionBar"> <item name="android:colorPrimary">@color/abc1</item> <item name="android:colorPrimaryDark">@color/abc2</item> <item name="android:colorAccent">@color/abc3</item> </style> 

But colors are ignored and replaced with the default turquoise color, and all dialog boxes appear without indentation.

Problemm

In addition, padding is also ignored in other places, such as custom toasts, the problem only occurs in devices with lollipops.

Edit:

The padding problem was due to fitsSystemWindow , and I solved it using
this question. .

But the problem of accent color still exists, and it affects not only the dialogs, but also the entire application.

+51
android android-5.0-lollipop material-design android-support-library appcompat android-appcompat
Oct 28 '14 at 12:28
source share
3 answers

About the color of the accent. You use the AppCompat theme to remove Android from the namespace inside your theme.

 <style name="AppTheme_Light" parent="Theme.AppCompat.Light.DarkActionBar"> <item name="colorPrimary">@color/abc1</item> <item name="colorPrimaryDark">@color/abc2</item> <item name="colorAccent">@color/abc3</item> </style> 

About the dialog box. AppCompat does not support it (as I know).
You can try using this style in the values ​​folder-v21:

 <style name="Theme" parent="FrameworkRoot.Theme"> <item name="android:alertDialogTheme">@style/Theme.AlertDialog</item> </style> <style name="Theme.AlertDialog" parent="android:Theme.Material.Light.Dialog.Alert"> <item name="android:colorPrimary">@color/demo_primary_color</item> <item name="android:colorPrimaryDark">@color/demo_colorPrimaryDark</item> <item name="android:colorAccent">@color/theme_accent_1</item> </style> 

UPDATE 04/23/2015: SUPPORT LIBRARY V.22.1

The new support library v22.1 works with a dialog box. You can use android.support.v7.app.AlertDialog or the new AppCompatDialog .

For example:

 import android.support.v7.app.AlertDialog AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.AppCompatAlertDialogStyle); builder.setTitle("Dialog"); builder.setMessage("Lorem ipsum dolor ...."); builder.setPositiveButton("OK", null); builder.setNegativeButton("Cancel", null); builder.show(); 

And use this style:

 <style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert"> <item name="colorAccent">#FFCC00</item> <item name="android:textColorPrimary">#FFFFFF</item> <item name="android:background">#5fa3d0</item> </style> 

Otherwise, you can define in the current topic:

 <style name="AppTheme" parent="Theme.AppCompat.Light"> <!-- your style --> <item name="alertDialogTheme">@style/AppCompatAlertDialogStyle</item> </style> 

and then in your code:

  import android.support.v7.app.AlertDialog AlertDialog.Builder builder = new AlertDialog.Builder(this); 
+125
Oct 28 '14 at 12:59 on
source share

update

I have successfully applied colors for AppCompat application dialogs, you might find it useful:

values ​​/ style.xml

 <style name="Theme.MyApp" parent="Theme.AppCompat.Light"> ... /* for android 4 - 4.4, we not define alert dialogs style */ </style> 

values-V21 / style.xml

 <style name="Theme.MyApp" parent="Theme.AppCompat.Light"> ... /* define alert dialog style for android 5 */ <item name="android:alertDialogTheme">@style/Theme.AlertDialog</item> </style> 

  <style name="Theme.AlertDialog" parent="Theme.AppCompat.Light.Dialog"> <!--app abar color in Activties Task manager --> <item name="colorPrimary">@color/my_color</item> <!--copy/paste colors --> <item name="colorAccent">@color/my_color</item> <!--status bar color --> <item name="colorPrimaryDark">@color/my_color</item> </style> 
+22
Jan 13 '15 at 16:13
source share

The current version of AppCompat does not apply coloring to AlertDialogs.

Try using https://github.com/afollestad/material-dialogs , it works great!

+8
Dec 01 '14 at 18:33
source share



All Articles