【问题标题】:Android Change branded launch background colors when theme is darkAndroid 在主题为深色时更改品牌启动背景颜色
【发布时间】:2019-11-16 15:11:56
【问题描述】:

我在我的应用程序中实现了深色主题。一切正常,当系统处于暗模式时,应用程序处于暗模式,反之亦然。

问题是 Branded Launch。我有 2 个可绘制文件:

黑暗:

<?xml version="1.0" encoding="utf-8"?>

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:opacity="opaque">

    <item android:drawable="@color/splashColorDark"/>

    <item>

        <bitmap
                android:src="@drawable/logo_branded"
                android:mipMap="true"
                android:gravity="center"/>

    </item>

</layer-list>

还有光:

 <?xml version="1.0" encoding="utf-8"?>

    <layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:opacity="opaque">

        <item android:drawable="@color/splashColorLight"/>

        <item>

            <bitmap
                    android:src="@drawable/logo_branded"
                    android:mipMap="true"
                    android:gravity="center"/>

        </item>

    </layer-list>

为了使用品牌发布,我添加了这个:

android:theme="@style/AppTheme.BrandedLaunchLight"

在我的AndroidManifest.xml

这样做显然我无法在暗模式处于活动状态时设置暗品牌启动。我该怎么办?

【问题讨论】:

    标签: android android-theme android-night-mode


    【解决方案1】:

    只需在您的应用中使用 DayNight 主题(Theme.MaterialComponents.DayNightTheme.AppCompat.DayNight)。
    然后在资源文件夹中使用-night qualifier 作为drawable-nightvalues-night

    这意味着在深色和浅色主题的品牌发布中为您的可绘制对象使用相同的名称,但使用 drawable-nightdrawable 文件夹。
    你可以对颜色做同样的事情。不要使用@color/splashColorDark@color/splashColorLight,而是使用单个名称splashColor 并将其放在values-night\colors.xmlvalues\colors.xml

    注意。检查official documentation

    启动屏幕

    如果您的应用具有自定义启动屏幕,则可能需要对其进行修改以反映所选主题。

    删除任何硬编码的颜色,例如任何指向的背景颜色都可能是白色。请改用 ?android:attr/colorBackground 主题属性

    请注意,dark-themed android:windowBackground drawables仅适用于 Android Q

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-16
      • 1970-01-01
      • 1970-01-01
      • 2015-06-27
      相关资源
      最近更新 更多