Android v21主题。Appcompat颜色重音被忽略,在对话框中没有填充

时间:2022-11-21 17:28:45

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

我使用的是Android 5 SDK的ActionBarActivity,这是我的主题。xml 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 the colors are ignored, and are replaced by a default teal color and all the dialogs appear without padding.

但是这些颜色会被忽略,取而代之的是一个默认的茶色,所有的对话框都没有填充。

Problem http://i62.tinypic.com/21cebcz.png

问题http://i62.tinypic.com/21cebcz.png

Also, padding is also ignored in other places like custom toast, problem only occurs in lollipop devices.

此外,在其他地方,例如自定义吐司,填充也被忽略,问题只出现在棒棒糖设备中。

Edit:

编辑:

The padding problem was due to fitsSystemWindow and I got it fixed using
this question..

填充问题是由fitsSystemWindow造成的,我用这个问题解决了这个问题。

But the accent color problem is still there, and it does not just affect dialogs but the whole app.

但是强调颜色的问题仍然存在,它不仅影响对话框,还影响整个应用程序。

3 个解决方案

#1


122  

About the accent color. You are using a AppCompat theme so you should remove Android from the namespace inside your theme.

关于口音的颜色。您正在使用AppCompat主题,因此应该从主题内的名称空间中删除Android。

<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. AppCompat doesn't support it (as I know).
You can try to use this style in your values-v21 folder:

关于对话框。AppCompat不支持它(我知道)。你可以尝试在你的values-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 23/04/2015: SUPPORT LIBRARY V.22.1

2015年4月23日更新:支持LIBRARY V.22.1

The new support library v22.1 works with the Dialog. You can use an android.support.v7.app.AlertDialog or the new AppCompatDialog.

新的支持库v22.1与对话框一起工作。你可以使用android.support.v7.app。AlertDialog或新的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 a style like this:

使用这样的风格:

<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 your current theme:

否则,您可以在当前主题中定义:

<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);

#2


20  

update

更新

I have applied successfully colors for appCompat dialogs themes , maybe be helpful for someone :

我已经成功应用了appCompat对话框主题的颜色,可能对某些人有帮助:

values/style.xml

值/ 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

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>

#3


8  

Current version of AppCompat doesn't apply colorization to AlertDialogs.

当前版本的AppCompat没有对AlertDialogs应用颜色化。

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

尝试使用https://github.com/afollestad/material-dialogs,它非常有用!

#1


122  

About the accent color. You are using a AppCompat theme so you should remove Android from the namespace inside your theme.

关于口音的颜色。您正在使用AppCompat主题,因此应该从主题内的名称空间中删除Android。

<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. AppCompat doesn't support it (as I know).
You can try to use this style in your values-v21 folder:

关于对话框。AppCompat不支持它(我知道)。你可以尝试在你的values-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 23/04/2015: SUPPORT LIBRARY V.22.1

2015年4月23日更新:支持LIBRARY V.22.1

The new support library v22.1 works with the Dialog. You can use an android.support.v7.app.AlertDialog or the new AppCompatDialog.

新的支持库v22.1与对话框一起工作。你可以使用android.support.v7.app。AlertDialog或新的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 a style like this:

使用这样的风格:

<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 your current theme:

否则,您可以在当前主题中定义:

<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);

#2


20  

update

更新

I have applied successfully colors for appCompat dialogs themes , maybe be helpful for someone :

我已经成功应用了appCompat对话框主题的颜色,可能对某些人有帮助:

values/style.xml

值/ 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

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>

#3


8  

Current version of AppCompat doesn't apply colorization to AlertDialogs.

当前版本的AppCompat没有对AlertDialogs应用颜色化。

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

尝试使用https://github.com/afollestad/material-dialogs,它非常有用!