【问题标题】:Can A WindowBackground Be Positioned Below The Status Bar & Above The Navigation Bar?可以将 WindowBackground 定位在状态栏下方和导航栏上方吗?
【发布时间】:2016-11-26 03:36:32
【问题描述】:

基于this tutorial 和this answer(也引用this other tutorial),使用主题的android:windowBackground 和<layer-list/> 似乎是最受认可的创建Android 启动画面的方法

使用这种技术使徽标在屏幕上居中很容易;但是,我想将图形放置在屏幕的顶部或底部。我遇到了问题,因为如下面的屏幕截图所示,windowBackground 似乎被绘制在屏幕顶部的状态栏和底部的导航栏后面,从而使图形看起来被截断



问题: 是否可以指示windowBackground 将自己定位在状态栏下方和导航栏上方?如果没有,使用windowBackground Splash Screen 技术是否可以创建一个不被状态栏或导航栏覆盖的初始屏幕?

要重现该问题,请创建一个新的 Android Studio 项目,该项目将为您提供 ic_launcher drawable 并按照上面链接的教程之一进行操作,但使用以下 layer-list drawable

<?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>

【问题讨论】:

    标签: android android-layout splash-screen android-theme


    【解决方案1】:

    您可以在棒棒糖和更高版本的主题中将windowDrawsSystemBarBackgrounds 设置为false。

    示例: 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-14
      • 1970-01-01
      • 2013-11-21
      相关资源
      最近更新 更多