2

我创建了一个 android 应用程序,当我将它下载到我的手机时,它以暗模式出现。

我希望我的应用程序始终处于光照模式,所以我使用了以下内容:

super.onCreate(savedInstanceState);
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);

但它仍然向我展示了黑暗模式下的应用程序。

我怎样才能完全禁用它?

我的styles.xml 文件是:

<style name="CustomActivityTheme" parent="@style/Theme.AppCompat.Light">
    <item name="android:actionBarStyle">@style/MyActionBar</item>
    <item name="actionBarStyle">@style/MyActionBar</item>
    <item name="android:windowActionBarOverlay">true</item>
    <!-- other activity and action bar styles here -->
</style>

<!-- style for the action bar backgrounds -->
<style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar">
    <item name="android:background">@color/colorGraySearchText</item>
    <item name="background">@color/colorGraySearch</item>
    <item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
    <item name="android:subtitleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
    <item name="titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
    <item name="subtitleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
</style>

<!-- Text -->
<style name="MyTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance">
    <item name="android:textColor">@color/colorGraySearchText</item>
    <item name="android:textSize">16dp</item>
</style>

<style name="CustomActivityTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

<style name="CustomActivityTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="CustomActivityTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

解决方案:

以下步骤解决了我的问题:

将我的 build.gradle (app) 更改为:

compileSdkVersion 29

targetSdkVersion 29

将以下行添加到我的 style.xml 中的任何样式:

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

谢谢

4

0 回答 0