闪屏活动背景色 [英] Splash screen activity background color

查看:27
本文介绍了闪屏活动背景色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Android 启动画面有问题.在长时间的应用程序启动期间向用户显示启动画面,但活动背景始终为黑色.我的意思是背景位图(初始图像)是可见的,但背景是黑色而不是白色.我使用的是透明的 PNG 图像.

I have problem with my splash screen on Android. Splash screen is displayed to the user during long application startup but activity background is always black. I mean background bitmap (splash image) is visible, but background is black instead of white. I'm using PNG image with transparency.

我有什么:

  1. 具有透明背景的 PNG 启动画面图像
  2. 启动画面活动

    [Activity(MainLauncher = true, Theme = "@style/Theme.Splash", NoHistory = true)]
    public class SplashScreen : Activity
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Do your app initialization here
            // Other long running stuff

            // Run app when done
            StartActivity(typeof(MainForm));
        }
    }

  1. resources/values/styles.xml 中启动屏幕活动的主题样式

    <resources>
      <style name="Theme.Splash" parent="@android:style/Theme.Holo.Light">
        <item name="android:windowBackground">@drawable/splash_centered</item>
        <item name="android:windowNoTitle">true</item>
      </style>
    </resources>

  1. Splash drawable 在 resources/drawable/splash_central.xml 中

    <bitmap xmlns:android="http://schemas.android.com/apk/res/android"
        android:src="@drawable/splash"
        android:gravity="center"
        android:background="@color/white"> <!-- this is ignored -->

问题:如您所见,我使用 Theme.Holo.Light 作为父主题,并且在我的应用程序的其余部分中使用它.全息光使用白色背景.此白色背景不适用于 SplashActivity 背景.SplashActivity 背景始终为黑色.背景位图(初始图像)可见,但背景是黑色而不是白色.我使用的是具有透明度的 PNG 图像.

Problem: As you can see, I'm using Theme.Holo.Light as parent theme and I'm using it in the rest of my app. Holo light is using white background. This white background is not applied on SplashActivity background. SplashActivity background is always black. Background bitmap (splash image) is visible, but background is black instead of white. I'm using PNG image with transparency.

问题:如何在 SplashScreen 活动中设置默认的 Holo.Light 主题背景颜色(白色)?

Question: How to set default Holo.Light theme background color (white) on the SplashScreen activity?

注意:我使用的是 Xamarin.Android,但 Android 平台的样式很常见.Android 4 及以上版本.

Note: I'm using Xamarin.Android, but styling is common for Android platform. Android version 4 and above.

推荐答案

在resources/drawable/splash_central.xml中,使用layer-list代替位图

In resources/drawable/splash_centered.xml, instead of the bitmap use a layer-list

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  <item>
    <shape android:shape="rectangle">
      <solid android:color="@android:color/white" />
    </shape>
  </item>
  <item>
    <bitmap android:gravity="center" android:src="@drawable/splash" />
  </item>
</layer-list>

这篇关于闪屏活动背景色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆