Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 647
Hatef Avatar asked Jul 02 '20 12:07

Hatef


People also ask

How do I enable dark themes in settings?

Open your device's Settings app . Select Accessibility. Under "Display," turn on Dark theme.

Does Miui have Dark Mode?

So with MIUI 12, Xiaomi brought a "Dark Mode 2.0" feature. This acted as a global filter, converting all light mode content on your screen to mimic the "dark mode" you can find today natively in many apps.


2 Answers

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>
like image 70
Hatef Avatar answered Oct 19 '22 09:10

Hatef


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

like image 41
riccardogabellone Avatar answered Oct 19 '22 10:10

riccardogabellone