在 MIUI 11 / 12 下激活暗模式时的主题问题

Hat*_*tef 14 colors nativescript

编辑:MIUI 强制在我的应用程序中激活暗模式,因此该应用程序看起来很糟糕。

在我的应用程序的某些部分中,当我将颜色设置为“白色”时,它将显示为白色。

如果我将其设置为“灰色”,它将显示为灰色。

如果我将其设置为“红色”,它将显示为红色。

但是:如果我将它设置为“黑色”,它将是“白色!”

我怎么解决这个问题??

Hat*_*tef 43

解决方案找到了!

将 false 设置为<item name="android:forceDarkAllowed">true</item> inApp_Resources/Android/src/main/res/values/styles.xml

感谢此链接:https : //medium.com/@kivind/nativescript-disabling-dark-mode-382e5dfd11bd

所以 style.xml 应该看起来像:

    <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>
Run Code Online (Sandbox Code Playgroud)

  • 不,这对我不起作用。MIUI 12.04 全球版。安卓10。 (4认同)
  • 确保 AppThemeBase 是 Manifest 中的主题,如下所示: android:theme="@style/AppThemeBase" 您可能还想在 res/values-v29 中创建一个单独的主题以保留 &lt;item name="android:forceDarkAllowed"&gt;假&lt;/项目&gt; (4认同)
  • 对我有用!重要的是,将其设置为“false”,盲目复制 true :D (2认同)

ric*_*one 10

结合许多不同的解决方案,我想出了这个演练

AppEntryPoint.kt

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

AndroidManifest.xml

<application
    android:name=".AppEntryPoint"
    ...
    android:theme="@style/Theme.MyMainTheme">
    ...
</application>
Run Code Online (Sandbox Code Playgroud)

themes.xml

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

</style>
Run Code Online (Sandbox Code Playgroud)

我不知道这是否是正确的解决方案,但现在它对我有用。在某些小米设备中可能有一种奇怪的方式来管理这种行为......

希望这个答案对其他人也有用