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 backg
This is how I was able to get white background splash (logo centred) in 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:
<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:
<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.
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>
set android:drawable="@color/colorWhite" to 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>