How to avoid forced dark mode in Material theme?

1.4k views Asked by At

I'm using Material theme. I want my app to be only in light theme (For now we don't have any plans for dark mode). Some devices force dark mode on apps and I want to avoid that.

I have seen this post on SO and unfortunately it doesn’t work for me.

So, how to solve this?

Styles.xml

   <resources>

    <!-- 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="colorAccent">@color/colorAccent</item>
        <item name="materialButtonStyle">@style/ButtonTheme</item>
    </style>

    <style name="LandingTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/White</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:buttonStyle">@style/ButtonTheme</item>
    </style>
</resoures>
1

There are 1 answers

7
Arvind On BEST ANSWER

Update: Some OEMs provide a dark-mode feature on an individual-app basis, which basically doesn't respect the forced-dark mode setting.

In that case, it is best to ignore any issues that relate to it. The user is warned about theming incompatibilities, which is a good thing from their side at the very least, if not respecting this setting.


Please do not account for uncontrollable factors such as overriding the force dark mode option (available inside Developer Options from Android 10+), which makes the opt-in/out effectively useless.

The feature is more of a trial-and-error, replacing light elements with their dark counterparts (basic but vague explanation, agreed) which may make-or-break an Application's User Experience.

There's a reason why it is meant only for Developers, and not made available as a "User" feature.