Emm*_*.bk 10 java xml android themes android-studio
问题是,当我查看软件上的预览时,一切都很好,但是当我在手机上运行该应用程序时,到处都使用白色,它会变暗(可绘制和背景)。我没有在可绘制对象上使用 alpha,只有android:color="@color/white".
问题的根源在于我的手机启用了夜间模式,因此它会自动更改应用程序中的颜色。
为了尝试禁用夜间模式,我创建了一个文件夹values-night并复制了我的 @styles 和 @colors 以匹配白天和夜间模式。
样式.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>
颜色.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"
我检查了如何在我的应用程序中禁用夜间模式的答案,即使在 android 9.0 (pie) 中启用了夜间模式?和android 9.0 中的 Dark Theme 改变了我的应用程序布局丑陋并做了values-night文件夹,但它没有解决问题。
但问题仍然存在,知道我在这里遗漏了什么吗?提前致谢。
小智 7
我在小米红米 Note 7 上遇到了同样的问题。我在里面试过这个代码MainActivity.create():
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
但它不适用于包括我在内的一些小米设备,尽管它适用于其他手机。
所以我找到的唯一解决方案是添加<item name="android:forceDarkAllowed" tools:targetApi="q">false</item>到您的每个AppThemein styles.xml. 像这样:
<style name="MyTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:forceDarkAllowed" tools:targetApi="q">false</item>
</style>
它适用于我的手机。
| 归档时间: | 
 | 
| 查看次数: | 6031 次 | 
| 最近记录: |