2

我想在我的应用程序(Android Q)中禁用暗模式..我厌倦了很多方法还没有得到解决方案。您能否为此提出完美的解决方案。

AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);

getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO); 
4

2 回答 2

1

将以下行添加到您的样式 xml。这将删除强制黑暗选项

 <item name="android:forceDarkAllowed" tools:targetApi="q">false</item>
于 2020-09-17T06:28:05.213 回答
0

也许您可以使用 onCreate 中的行在整个应用程序中禁用它

AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)

或仅针对单个活动:

getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO);

之后,您将需要 recreate() 才能再次使用它。

于 2020-09-17T06:35:53.627 回答