即使在android 9.0(pie)中启用了夜间模式,如何在我的应用程序中禁用夜间模式?

即使在android 9.0(pie)中启用了夜间模式,如何在我的应用程序中禁用夜间模式?

问题描述:

我在发布android pie之前创建了我的应用程序,在我放置的每个布局中, android:background ="white" 在所有设备上都可以正常工作,但是当我的兄弟安装了该应用程序并启用时夜间模式我的应用程序一动不动就变成了一场灾难,一切都变成了黑白电影.

I created my application before the android pie has been released, in every layout I put android: background = "white" it works fine in every device, but when my brother installed the application and enabled night mode my application becomes a disaster with one single move, everything turns into back and white movie.

<style name="AppTheme" parent="Theme.AppCompat.DayNight.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/COLOR_PRIMARY</item>
    <item name="colorPrimaryDark">@color/COLOR_PRIMARY</item>
    <item name="colorAccent">@color/COLOR_PRIMARY</item>
    <item name="cardViewStyle">@style/CardView</item>
    <item name="android:fontFamily">@font/helvetica</item>
</style>

我的原色是红色.

您可以将其放在启动器活动的 onCreate 方法的第一行.

You can put this, at the first line in the onCreate method of your launcher activity.

    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)