【问题标题】:How can I disable Night Mode in Android 11?如何在 Android 11 中禁用夜间模式?
【发布时间】:2021-02-12 06:47:45
【问题描述】:

我尝试删除夜间theme.xml,并尝试在夜间主题中进行颜色更改。我也试过了

AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);

但这些都不起作用。

这是我的theme.xml

<resources xmlns:tools="http://schemas.android.com/tools">
    <!-- Base application theme. -->
    <style name="Theme.app" parent="Theme.AppCompat.DayNight.NoActionBar">
        <!-- Primary brand color. -->
        <item name="colorPrimary">@color/light_blue</item>
        <item name="colorPrimaryVariant">@color/light_blue</item>
        <item name="colorOnPrimary">@color/white</item>
        <!-- Secondary brand color. -->
        <item name="colorSecondary">@color/teal_200</item>
        <item name="colorSecondaryVariant">@color/teal_700</item>
        <item name="colorOnSecondary">@color/black</item>
        <!-- Status bar color. -->
        <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
        <!-- Customize your theme here. -->
    </style>

</resources>

我该怎么做?

【问题讨论】:

    标签: java android android-studio android-dark-theme


    【解决方案1】:

    只需更改两个主题文件

    <style name="Theme" parent="Theme.MaterialComponents.Light.NoActionBar">
    

    【讨论】:

      【解决方案2】:

      将此添加到您的应用主题中

      <item name="android:forceDarkAllowed">false</item>
      

      【讨论】:

        【解决方案3】:

        (以上两个答案!并且它适用于jetpack compose)

        更改两个主题文件
        <style name="Theme.PathFinder" parent="Theme.MaterialComponents.Light.DarkActionBar">
        

        并将其添加到两个主题文件中

        <item name="android:forceDarkAllowed" tools:targetApi="q">false</item>
        

        【讨论】:

          【解决方案4】:

          在您的样式声明中,尝试将父级直接更改为Light,如下所示:

          <style name="Theme.app" parent="Theme.AppCompat.Light.NoActionBar">
          

          【讨论】:

          • 还是不行
          • @Faizan 它在小米设备上不起作用你应该将此代码添加到你的设备中 false
          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2019-12-02
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-02-14
          • 1970-01-01
          相关资源
          最近更新 更多