WindowBackground可以定位在状态栏下方和导航栏上方吗?

For*_*ice 12 android splash-screen android-layout android-theme

基于本教程这个答案,也引用了这个其他教程,使用主题android:windowBackground和一个<layer-list/>似乎是最批准的创建Android启动画面的方法

使用这种技术将徽标集中在屏幕上很容易; 但是,我想在屏幕的顶部或底部放置图形.我遇到了问题,因为如下面的屏幕截图所示,windowBackground屏幕顶部的状态栏和底部的导航栏背后都显示出来,因此图形显示为截止



问题: 是否可以指示将windowBackground自己定位在状态栏下方和导航栏上方?如果没有,使用windowBackground启动画面技术是否可以创建状态栏或导航栏未涵盖的启动画面?

要重现该问题,请创建一个新的Android Studio项目,该项目将为您提供ic_launcherdrawable并按照上面链接的其中一个教程但使用以下layer-listdrawable

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:opacity="opaque">
    <item android:drawable="#000000"/>
    <item>
        <bitmap
            android:gravity="left|top"
            android:src="@drawable/ic_launcher"/>
    </item>
    <item>
        <bitmap
            android:gravity="center"
            android:src="@drawable/ic_launcher"/>
    </item>
    <item>
        <bitmap
            android:gravity="bottom"
            android:src="@drawable/ic_launcher"/>
    </item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)

Ugu*_*men 14

你可以设置windowDrawsSystemBarBackgroundsfalse你的主题棒棒糖和更高版本.

示例:res/values-v21/styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <style name="Theme.Splash">
        <item name="android:windowBackground">@drawable/splash</item>
        <item name="android:windowDrawsSystemBarBackgrounds">false</item>
    </style>
</resources>
Run Code Online (Sandbox Code Playgroud)

  • 这完全符合要求,谢谢. (2认同)