Android v21 Theme.Appcompat颜色重音被忽略,对话框没有填充

k1s*_*lay 51 android android-appcompat android-support-library material-design android-5.0-lollipop

我使用ActionBarActivity从Android 5 SDK,这里是我的theme.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>
Run Code Online (Sandbox Code Playgroud)

但颜色被忽略,并被默认的蓝绿色替换,所有对话框都显示没有填充.

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

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

编辑:

填充问题是由于fitsSystemWindow我解决了
这个问题..

但是重音颜色问题仍然存在,它不仅影响对话框而且影响整个应用程序.

Gab*_*tti 125

关于强调色.您正在使用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>
Run Code Online (Sandbox Code Playgroud)

关于对话框.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>
Run Code Online (Sandbox Code Playgroud)

更新23/04/2015:支持图书馆V.22.1

新的support library v22.1工作与Dialog.您可以使用android.support.v7.app.AlertDialog或新的AppCompatDialog.

例如:

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();
Run Code Online (Sandbox Code Playgroud)

并使用这样的风格:

<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>
Run Code Online (Sandbox Code Playgroud)

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

<style name="AppTheme" parent="Theme.AppCompat.Light">
    <!-- your style -->
    <item name="alertDialogTheme">@style/AppCompatAlertDialogStyle</item>
</style>
Run Code Online (Sandbox Code Playgroud)

然后在你的代码中:

 import android.support.v7.app.AlertDialog

    AlertDialog.Builder builder =
           new AlertDialog.Builder(this);
Run Code Online (Sandbox Code Playgroud)

  • 好的,首先,我很荣幸能够通过cards-lib的创建者回答我的问题.填充问题是由于"fitsSystemWindow"引起的,我使用[这个问题]修复了它.(http://stackoverflow.com/questions/26599805/android-alert-dialog-not-styled-properly-on-lollipop?rq = 1)编辑:关于重音颜色,它不仅限于对话框,而是在任何地方都被忽略 (4认同)
  • 在android 4.2.2中它不工作的对话框和对话框的背景看起来不同么?看起来不像lolipop对话框 (3认同)
  • 删除`android:`工作.非常感谢. (2认同)
  • @GabrieleMariotti请注意,如果在应用程序主题中定义`alertDialogTheme`属性,则不需要将样式传递给`AlertDialog.Builder`.见[here](http://stackoverflow.com/a/29799142/356895). (2认同)

Ser*_*nko 22

更新

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

值/ style.xml

<style name="Theme.MyApp" parent="Theme.AppCompat.Light">

...

/* for android 4 - 4.4, we not define alert dialogs style */

</style>
Run Code Online (Sandbox Code Playgroud)

值-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>
Run Code Online (Sandbox Code Playgroud)

 <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>
Run Code Online (Sandbox Code Playgroud)


Ale*_*sky 8

当前版本的AppCompat不会将颜色应用于AlertDialogs.

尝试使用https://github.com/afollestad/material-dialogs,它很棒!