[英]Splash screen activity background color
I have problem with my splash screen on Android. 我在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.
我正在使用具有透明度的PNG图像。
What I have: 我有的:
[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));
}
}
<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>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/splash"
android:gravity="center"
android:background="@color/white"> <!-- this is ignored -->
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. 问题:正如你所看到的,我正在使用Theme.Holo.Light作为父主题,我在我的应用程序的其余部分使用它。 Holo light is using white background.
Holo光使用白色背景。 This white background is not applied on SplashActivity background.
此白色背景不适用于SplashActivity背景。 SplashActivity background is always black.
SplashActivity背景总是黑色的。 Background bitmap (splash image) is visible, but background is black instead of white.
背景位图(启动图像)可见,但背景为黑色而不是白色。 I'm using PNG image with transparency.
我正在使用具有透明度的PNG图像。
Question: How to set default Holo.Light theme background color (white) on the SplashScreen activity? 问题:如何在SplashScreen活动中设置默认的Holo.Light主题背景颜色(白色)?
Note: I'm using Xamarin.Android, but styling is common for Android platform. 注意:我使用的是Xamarin.Android,但Android平台的样式很常见。 Android version 4 and above.
Android版本4及更高版本。
In resources/drawable/splash_centered.xml, instead of the bitmap use a layer-list 在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>
This is how I was able to get white background splash (logo centred) in Xamarin. 这就是我在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)));
}
}
with Theme.Splash as: 使用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>
and splash.axml code (Theme.Light.NoTitleBar) as: 和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>
NB: There is a slight delay in the splash png (logo) to come up, but its still acceptable, better than the black background. 注意:飞溅png(徽标)稍有延迟,但它仍然可以接受,比黑色背景更好。
set android:drawable="@color/colorWhite" to item. 将android:drawable =“@ color / colorWhite”设置为item。
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/colorWhite" />
<item>
<bitmap
android:gravity="center"
android:src="@drawable/splash" />
</item>
</layer-list>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.