启动画面活动背景色 [英] Splash screen activity background color

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

问题描述

我在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. 在资源/drawable/splash_centered.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_centered.xml中,使用位列表代替位图

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天全站免登陆