使用 AppCompatTheme 的前棒棒糖设备上的颜色错误
Wrong colors on pre-lollipop devices with AppCompatTheme
我的 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 和上层设备上一切正常,但在 Lollipop 之前的设备上有错误的颜色。看起来主题不适用于棒棒糖 android 之前版本的设备。谷歌搜索后,我发现建议人们在 AppCompat 主题中的每个项目之前删除 'android:' 前缀,但这对我不起作用,因为 android 工作室在那之后看不到项目。
colorPrimary、colorPrimaryDark 和 colorAccent 项目仅在 API 21+ 上可用。如果您想将它们应用到棒棒糖之前的设备上,您必须将当前的 styles.xml 文件移动到 values-v21 并创建在 values 文件夹上新建 styles.xml,并为 pre lollipop 使用正确的项目。
查看 android 开发人员了解更多 https://developer.android.com/guide/topics/ui/themes.html
原因是我没有扩展AppCompatActivity。当我改变它时,一切都好了。
我的 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 和上层设备上一切正常,但在 Lollipop 之前的设备上有错误的颜色。看起来主题不适用于棒棒糖 android 之前版本的设备。谷歌搜索后,我发现建议人们在 AppCompat 主题中的每个项目之前删除 'android:' 前缀,但这对我不起作用,因为 android 工作室在那之后看不到项目。
colorPrimary、colorPrimaryDark 和 colorAccent 项目仅在 API 21+ 上可用。如果您想将它们应用到棒棒糖之前的设备上,您必须将当前的 styles.xml 文件移动到 values-v21 并创建在 values 文件夹上新建 styles.xml,并为 pre lollipop 使用正确的项目。
查看 android 开发人员了解更多 https://developer.android.com/guide/topics/ui/themes.html
原因是我没有扩展AppCompatActivity。当我改变它时,一切都好了。