简体   繁体   English

即使使用浅色主题,系统也无法在我的应用中禁用强制暗模式。 如何解决?

[英]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.

相关问题 如何在 Material 主题中避免强制暗模式? - How to avoid forced dark mode in Material theme? 如何在 android 中使用开关实现暗/亮模式主题,同时忽略系统主题 - How to implement dark/light mode theme with switch in android while ignoring system theme 如何使用可组合物在应用程序中动态切换明暗主题 - How to switch between light and dark theme dynamically in app using composables 如何强制Android应用程序的用户界面点亮模式 - how to forced UI of android app to light mode 当设备可以在应用程序级别强制使用时,如何避免在我的应用程序中强制使用深色主题? - How to avoid forced dark theme in my app when devices can force it at app level? 如何正确测试所选主题是亮模式还是暗模式 - How to properly test if selected theme is light mode or dark mode 如何检测手机系统是深色主题还是浅色主题? - How to detect phone system is dark theme or light theme? 如何在 Android java 应用程序中保持相同的主题? 在 android 手机的暗光模式下 - How to maintain the same theme in Android java app ? in both dark and light mode of android mobile 即使设置了深色主题,是否可以以某种方式强制使用浅色主题的本机对话框(例如启用融合位置)? - Can be native dialog (e.g. fused location enable) somehow forced to have light theme even though dark theme is set? 带有Light App主题的深色工具栏 - Dark Toolbar with Light App Theme
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM