我想在我的应用程序(Android Q)中禁用暗模式..我厌倦了很多方法还没有得到解决方案。您能否为此提出完美的解决方案。
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO);
我想在我的应用程序(Android Q)中禁用暗模式..我厌倦了很多方法还没有得到解决方案。您能否为此提出完美的解决方案。
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO);
将以下行添加到您的样式 xml。这将删除强制黑暗选项
<item name="android:forceDarkAllowed" tools:targetApi="q">false</item>
也许您可以使用 onCreate 中的行在整个应用程序中禁用它
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
或仅针对单个活动:
getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO);
之后,您将需要 recreate() 才能再次使用它。