【问题标题】:Wrong colors on pre-lollipop devices with AppCompatTheme带有 AppCompatTheme 的棒棒糖前设备上的颜色错误
【发布时间】:2016-10-02 11:04:22
【问题描述】:

我的 style.xml 文件中有这个

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
    <!-- Customize your theme here. -->
    <!--<item name="colorPrimary">@color/colorPrimary</item>-->
    <!--<item name="colorAccent">@color/colorAccent</item>-->
    <item name="android:windowBackground">@color/white</item>
    <item name="android:windowTranslucentStatus">true</item>
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

<style name="LoginScreenTheme" parent="AppTheme">
    <item name="android:textColor">@color/white</item>
    <item name="colorAccent">@color/white</item>
    <item name="colorPrimaryDark">@color/login_background_dark</item>
</style>

<style name="LoginEditTextTheme" parent="AppTheme">
    <item name="colorControlNormal">@color/login_edit_text_hint_color</item>
    <item name="colorControlActivated">@color/login_edit_text_accent</item>
    <item name="colorControlHighlight">@color/login_edit_text_accent</item>
    <item name="android:textColorHint">@color/login_edit_text_hint_color</item>
    <item name="android:textColorPrimary">@color/white</item>
</style>

<style name="LoginErrorFloatingLabelTheme" parent="TextAppearance.AppCompat.Small">
    <item name="android:textColor">@color/login_error_floating_label_color</item>
</style>

<style name="ActionBarTheme" parent="AppTheme">
    <item name="android:background">@color/home_primary_color</item>
</style>

<style name="LoginWaitingProgressBar" parent="AppTheme">
    <item name="colorAccent">@color/orange_light</item>
</style>

</resources>

在带有 Lollipop 和上部的设备上一切正常,但在 pre-lollipop 上出现错误的颜色。看起来主题不适用于具有 pre-lollipop android 版本的设备。谷歌搜索后,我发现建议人们在 AppCompat 主题中的每个项目之前删除“android:”前缀,但这对我不起作用,因为 android studio 在那之后看不到项目。

【问题讨论】:

    标签: android colors styles themes android-appcompat


    【解决方案1】:

    原因是我没有扩展 AppCompatActivity。当我改变它时,一切都好了。

    【讨论】:

      【解决方案2】:

      colorPrimary 、 colorPrimaryDark 和 colorAccent 项目仅在 API 21+ 上可用。如果你想在棒棒糖之前的设备上应用它们,你必须将当前的 styles.xml 文件移动到 values-v21 并在 values 文件夹上创建一个新的 styles.xml并为棒棒糖使用正确的项目。

      查看安卓开发者了解更多https://developer.android.com/guide/topics/ui/themes.html

      【讨论】:

        猜你喜欢
        • 2016-02-11
        • 2018-09-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-21
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多