You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Android 9中禁用深色模式?现有方案仅Android10+生效

问题:Android 9中无法禁用深色模式,Android 10+正常生效

我正尝试在应用中禁用深色模式,该设置在Android 10及以上版本可正常生效,但在Android 9中无法实现,恳请各位提供帮助,谢谢!

已尝试的操作

1. 主题配置

在theme和theme(night)文件中均配置了如下主题代码:

<style name="Theme.VideoTradieProvider" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!--    <style name="Theme.VideoTradieProvider" parent="Theme.MaterialComponents.Light.NoActionBar">-->
        <!-- Primary brand color. -->

        <item name="android:windowActivityTransitions">true</item>

<!--        <item name="android:windowEnterTransition">@transition/explode_old</item>-->
<!--        <item name="android:windowExitTransition">@transition/explode_old</item>-->

        <item name="colorPrimary">@color/purple_500</item>
        <item name="colorPrimaryVariant">@color/purple_700</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">@color/white</item>
        <item name="android:windowLightStatusBar">true</item>
        <!-- Customize your theme here. -->
    </style>

2. 代码设置

在onCreate方法中添加了以下代码,但Android 9中仍不生效:

AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)

内容的提问来源于stack exchange,提问作者Testing Netscapelabs

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 06:25:38