android - 即使使用浅色主题,系统也无法在我的应用中禁用强制暗模式。如何解决?
问题描述
致版主:这不是一个重复的问题。我已经尽力了。StackOverflow 的解决方案。
我使用 Theme.MaterialComponents.Light.NoActionbar 作为 styles.xml 文件中的父主题。
我的样式.xml:
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="android:forceDarkAllowed" tools:targetApi="q">false</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">#00000000</item>
<item name="snackbarStyle">@style/MySnackbar</item>
</style>
<style name="AppTheme2" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:forceDarkAllowed" tools:targetApi="q">false</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:navigationBarColor">#00000000</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="snackbarStyle">@style/MySnackbar</item>
</style>
</resources>
我的应用程序类代码:
public class Extendit extends Application {
@Override
public void onCreate() {
super.onCreate();
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
}
}
应用程序类附加在清单文件中。此外,AppTheme 是应用程序的基本主题。
androidmanifest.xml:
<application
android:name=".Extendit"
android:allowBackup="true"
android:appComponentFactory="df"
android:icon="@mipmap/iconx"
android:label="@string/app_name"
android:largeHeap="true"
android:roundIcon="@mipmap/iconx"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:replace="android:appComponentFactory">
我还在styles.xml 中添加了“forcedarkallowed”错误标志并删除了styles.xml(night) 文件。
PS 我正在使用 Realme 设备。
解决方案
明白了事实。问题出在设备和 Realme Android 9.0 操作系统上。它不允许您以任何方式拥有自己的白天或夜晚主题,而是迫使您拥有系统当前拥有的内容。
推荐阅读
- hana - SAP HANA 计算视图,带有 SQL 脚本的计算列
- python - 如何在 Service Fabric 应用程序中运行 pythonnet (Keras.Net)?
- opengl - 如何从 Rust 中的其他线程绘制 OpenGL 三角形
- python - 如何在 Tensorflow / Keras 中为具有多个标签的字典形式的数据集定义损失?
- python - TypeError: unhashable type: 'numpy.ndarray' 将元组转换为集合
- spring - 使用外部 api 时 mime 类型无效
- c# - 如何在 Razor pages .Net 核心项目中访问 html 文件
- bash - bash exec 与不同的用户没有额外的过程
- php - 文件不在允许的路径内,但实际上是
- advanced-installer - 高级安装程序:查询结果未存储在属性中