飞溅屏幕活动背景颜色

Lud*_*dwo 20 android splash-screen xamarin

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

是)我有的:

  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));
        }
    }
Run Code Online (Sandbox Code Playgroud)
  1. 资源/ 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>
Run Code Online (Sandbox Code Playgroud)
  1. Splash drawable in resources/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 -->
Run Code Online (Sandbox Code Playgroud)

问题: 正如你所看到的,我正在使用Theme.Holo.Light作为父主题,我在我的应用程序的其余部分使用它.Holo光使用白色背景.此白色背景不适用于SplashActivity背景.SplashActivity背景总是黑色的. 背景位图(启动图像)可见,但背景为黑色而不是白色.我正在使用具有透明度的PNG图像.

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

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

Jon*_*ing 35

在resources/drawable/splash_centered.xml中,使用图层列表而不是位图

<?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>
Run Code Online (Sandbox Code Playgroud)


Shi*_*bbs 9

这就是我在Xamarin中获得白色背景飞溅(徽标居中)的方式.

[Activity (Theme= "@style/Theme.Splash", MainLauncher=true, NoHistory=true)]            
public class SplashActivity : Activity
{
    protected override void OnCreate (Bundle bundle)
    {
        base.OnCreate (bundle);
        SetContentView (Resource.Layout.splash);
        ThreadPool.QueueUserWorkItem (o => LoadActivity ());
        // Create your application here
    }
    private void LoadActivity() {
        Thread.Sleep (1000); // Simulate a long pause
        RunOnUiThread (() => StartActivity (typeof(MainActivity)));
    }
}
Run Code Online (Sandbox Code Playgroud)

使用Theme.Splash:

<resources>
  <style name="Theme.Splash" parent="@android:style/Theme.Light">
    <item name="android:colorBackground">@android:color/white</item>
    <item name="android:windowNoTitle">true</item>
  </style>
</resources>
Run Code Online (Sandbox Code Playgroud)

和splash.axml代码(Theme.Light.NoTitleBar)为:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:minWidth="25px"
    android:minHeight="25px"
    android:gravity="center">
    <ImageView
        android:src="@drawable/splash"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView1"
        android:layout_gravity="center" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

注意:飞溅png(徽标)稍有延迟,但它仍然可以接受,比黑色背景更好.