Theme Problem when Dark Mode is activated under MIUI 11 / 12
Asked Answered
S

3

31

EDIT: MIUI force Dark Mode to be activated in my app, so the app looks awful.

In some Part of my app when I set Color to "white", it will be shown as White.

If I set it as "gray", it will be shown as Gray.

If I set it as "red", it will be shown as Red.

but: If I set it as "black", it will be "WHITE!"

How can I solve this problem??

Sauer answered 2/7, 2020 at 12:27 Comment(0)
S
73

Solution is Found!

Setting false to the <item name="android:forceDarkAllowed">true</item> in App_Resources/Android/src/main/res/values/styles.xml

Thanks to this link: https://medium.com/@kivind/nativescript-disabling-dark-mode-382e5dfd11bd

so style.xml should looks like:

    <style name="AppThemeBase" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="toolbarStyle">@style/NativeScriptToolbarStyle</item>
        <item name="android:forceDarkAllowed">false</item>
        <item name="colorPrimary">@color/ns_primary</item>
        <item name="colorPrimaryDark">@color/ns_primaryDark</item>
        <item name="colorAccent">@color/ns_accent</item>
    </style>
Sauer answered 4/7, 2020 at 18:5 Comment(7)
Nope, that does not work for me. MIUI 12.04 Global. Android 10.Mendez
Make sure that AppThemeBase is your theme in Manifest, like this: android:theme="@style/AppThemeBase" You may also want to make a separate theme in res/values-v29 to keep <item name="android:forceDarkAllowed">false</item>Lorinalorinda
@Pixza I am using MIUI 12 and it works fine. Please chillSylvester
Works for me! Important to set it to false, blindly copied the true :DGallbladder
<item name="android:forceDarkAllowed">false</item> requires API level 29. I have API level 21. How can I solve the issue of dark mode on Xiaomi ?Transitive
it might help @Transitive : <item name="android:forceDarkAllowed" tools:targetApi="q">false</item>Commie
@Ani: <resources xmlns:tools="schemas.android.com/tools"> ...<item name="android:forceDarkAllowed" tools:targetApi="29">false</item>Avian
P
22

Meshing up many different solutions, I figured out this walktrough

AppEntryPoint.kt

class AppEntryPoint : Application() {
    override fun onCreate() {
        super.onCreate()
        /*in some XIAOMI devices seems to be necessary*/
        AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
    }
}

AndroidManifest.xml

<application
    android:name=".AppEntryPoint"
    ...
    android:theme="@style/Theme.MyMainTheme">
    ...
</application>

themes.xml

<style name="Theme.MyMainTheme" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
    ...
    <item name="android:forceDarkAllowed" tools:targetApi="q">false</item>

</style>

I don't know if it is the correct solution, but now it works for me. There's maybe a strange way to manage this kind of behaviour in some Xiaomi devices...

Hope this answer could be useful also to others

Paulus answered 5/5, 2021 at 10:8 Comment(1)
So useful! I've been beating my head against the desk for 3 days over colours mysteriously changing without any apparent reason. #74541353 ThanksEbersole
N
-1

On xiaomi redmi 9 at least had got to set this value false on both night and day themes.xml files. and work like a charm.

Nonsuch answered 12/12, 2021 at 2:24 Comment(1)
What value has to be set???Modred

© 2022 - 2024 — McMap. All rights reserved.