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??
Open your device's Settings app . Select Accessibility. Under "Display," turn on Dark theme.
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.
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>
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With