How to avoid forced dark theme in my app when devices can force it at app level?
Asked Answered
F

2

8

Some devices, like Poco F2 Pro, can force dark theme in apps that are not compatible with dark theme.

For example, my app has this theme and is not compatible with dark theme:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

This is my manifest application part, no dark theme enabled:

<application
    android:name=".helpers.CustomApplication"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:largeHeap="true"
    android:theme="@style/AppTheme">

The problem is that devices like Poco F2 Pro, when forcing dark theme in apps, makes my app to be displayed with incorrect and abnormal colors, breaking the UI.

Can that be avoided?

How to force dark theme: https://www.androidauthority.com/android-q-force-dark-mode-984090

Ferreira answered 7/9, 2020 at 12:14 Comment(1)
can you share your manifest file as wellKyrstin
E
17

You can disable Force Dark in your app by setting a flag in your theme:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:forceDarkAllowed">false</item>
</style>
Electrocute answered 15/9, 2020 at 10:38 Comment(1)
NOTE: You will need to put this into app/src/main/res/values-v29/styles.xml if you support a lower Android API minimum than 29. This directory (and the styles defined in it) will only be used on devices that are running 29+.Hildebrandt
P
7

This is an old question, but I thought to post my solution so it may help others.

Change your app theme parent from

parent="Theme.MaterialComponents.DayNight.DarkActionBar"

to

parent="Theme.MaterialComponents.Light.DarkActionBar"
Pulmonary answered 21/10, 2022 at 5:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.