30

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??

Hatef
  • 1,168
  • 1
  • 7
  • 15

3 Answers3

72

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>
Hatef
  • 1,168
  • 1
  • 7
  • 15
20

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

riccardogabellone
  • 268
  • 1
  • 6
  • 17
  • 1
    So useful! I've been beating my head against the desk for 3 days over colours mysteriously changing without any apparent reason. https://stackoverflow.com/questions/74540853/colour-coming-out-wrong-when-painting-on-android-canvas/74555562#74555562 Thanks – interstar Nov 24 '22 at 04:17
-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.