【发布时间】:2020-12-26 02:23:20
【问题描述】:
问题是,当我在软件上查看预览时,一切都很好,但是当我在手机上运行该应用程序时,到处都使用白色,它变暗(可绘制对象和背景)。我没有在drawables上使用alpha,只有android:color="@color/white"。
问题的根源是我的手机启用了夜间模式,所以它会自动更改应用程序中的颜色。
为了尝试禁用夜间模式,我创建了一个文件夹 values-night 并复制了我的 @styles 和 @colors 以匹配白天和夜间模式。
styles.xml(夜晚)
<resources>
<!-- Base application theme. -->
<style name="MyTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:windowBackground">@color/colorAccent</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
colors.xml(夜晚)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#1d1d1d</color>
<color name="colorPrimaryDark">#1d1d1d</color>
<color name="colorAccent">#F8F8F8</color>
<color name="textColor">#1d1d1d</color>
</resources>
在我的 MainActivity.xml 中
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:background="@color/colorAccent"
android:theme="@style/MyTheme"
android:layout_height="match_parent"
tools:context=".MainActivity">
在我的 Manifest.xml 中
android:theme="@style/MyTheme"
我检查了How to disable night mode in my application even if night mode is enable in android 9.0 (pie)? 和Dark Theme in android 9.0 changes my app layouts ugly 上的答案,并做了values-night 文件夹,但它没有解决问题。
但是问题仍然存在,知道我在这里缺少什么吗?提前致谢。
【问题讨论】:
标签: java android xml android-studio themes