当切换到暗模式时,使用 Theme.MaterialComponents.Light 仍然会改变 MIUI 中的颜色,但在 Stock Android 中工作正常,为什么?

问题描述

基本上,我想声明一个静态主题,这样我的应用程序在所有设备上看起来都一样,但发现这种奇怪的行为,即切换到暗模式不会改变库存 android 中的颜色(在模拟器和一个 plus7T Pro 中测试)但是在 MIUI 中切换到暗模式会改变颜色我正在使用 MaterialComponents.Light 主题,并且 build.gradle 文件中还存在 Material 主题依赖项。

显示这种奇怪行为的设备配置:-

MIUI 版本为 12.0.4 Stable,设备为 Redmi Note 7 Pro Android 版本 10。

这是我的清单文件:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.android.lightdark">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.MaterialComponents.Light.NoActionBar.Bridge">
        <activity android:name=".MainActivity"
            android:theme="@style/Theme.MaterialComponents.Light.NoActionBar.Bridge">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

这是我的 build.gradle

plugins {
    id 'com.android.application'
    id 'kotlin-android'
}

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.2"

    defaultConfig {
        applicationId "com.android.lightdark"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
}

dependencies {

    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.3.2'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.2.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

我的代码很可能有问题,因为我还安装了一些应用程序,它们在切换到暗模式后不会改变颜色。

我还发现我的应用程序默认在高级黑暗模式设置中打开。我不知道如何防止我的应用在 MIUI 的高级黑暗模式设置中默认关闭,而 Facebook、Whatsapp 等应用默认处于关闭状态。

MIUI Advanced Dark Mode Settings Screenshot

My App by default turned on in this setting

手动关闭此功能可以解决我的问题,但我想知道为什么默认情况下会打开此功能以及如何防止这种情况发生?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...