[英]Cannot disable forced dark mode in my app by system even by using light theme. how to fix it?
To moderators: this is not a duplicate question.致版主:这不是一个重复的问题。 I've tried all avail.
我已经尽力了。 solutions from StackOverflow.
StackOverflow 的解决方案。
I've used Theme.MaterialComponents.Light.NoActionbar as a parent theme in styles.xml file.我在 styles.xml 文件中使用了 Theme.MaterialComponents.Light.NoActionbar 作为父主题。
my styles.xml:我的 styles.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>
My application class code:我的应用程序 class 代码:
public class Extendit extends Application {
@Override
public void onCreate() {
super.onCreate();
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
}
}
The application class is attached in the manifest file.应用程序 class 附加在清单文件中。 Also, the AppTheme is the base theme of application.
此外,AppTheme 是应用程序的基本主题。
androidmanifest.xml: 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">
I've also added "forcedarkallowed" false flag in styles.xml and deleted the styles.xml(night) file.我还在 styles.xml 中添加了“forcedarkallowed”错误标志,并删除了 styles.xml(night) 文件。
PS I'm using Realme device. PS 我正在使用 Realme 设备。
Add this in your styles.xml file:将此添加到您的 styles.xml 文件中:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="android:forceDarkAllowed" tools:targetApi="q">false</item>
</style>
And in your AppTheme use this in parent:在您的 AppTheme 中,在父级中使用它:
parent="Theme.MaterialComponents.Light.DarkActionBar"
Got the fact.明白了事实。 The issue is with device and Realme Android 9.0 OS.
问题出在设备和 Realme Android 9.0 操作系统上。 It doesn't allow you to have your own day or night theme in any way, rather it forces you to have what the system is currently having.
它不允许您以任何方式拥有自己的白天或夜晚主题,而是迫使您拥有系统当前拥有的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.