Implement splash screen. how do I specify the image size?

113 views Asked by At

I do splash screen, but the problem is that I do not know where to add styles. how do I specify the image size ? How do I add text ?

[Activity(Label = "SplashActivity", Theme = "@style/Theme.Splash", MainLauncher = true)]
public class SplashScreen : Activity
{
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        StartActivity(typeof(MainActivity));
        Finish();
        OverridePendingTransition(0, 0);
    }
}

` In drawable folder splash_screen.xml:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<color android:color="@color/splash_background"/>
  </item>
  <item>
   <bitmap
    android:src="@drawable/splash_logo"
    android:tileMode="disabled"
    android:gravity="center"
    />
  </item>
  </layer-list>

Folder values, style.xml:

<style name="Theme.Splash" parent ="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">@drawable/splash_screen</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowActionBar">true</item>
</style>
1

There are 1 answers

1
Alessandro Caliaro On BEST ANSWER

I think you have two options. 1- create an image and visualize it (as in your sample) 2- create an activity layout, so you can add image, text... what you want

You can find some info in the official documentation: Xamarin.Forms SplashScreen

and here you can find the Android Sample: Xamarin.Android SplashScreen

In this sample, you have a style with a drawable:

<resources>
  <style name="MyTheme.Base" parent="Theme.AppCompat.Light">
  </style>

    <style name="MyTheme" parent="MyTheme.Base">
  </style>

  <style name="MyTheme.Splash" parent ="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowBackground">@drawable/splash_screen</item>
    <item name="android:windowNoTitle">true</item>  
    <item name="android:windowFullscreen">true</item>  
    <item name="android:windowContentOverlay">@null</item>  
    <item name="android:windowActionBar">true</item>  
  </style>
</resources>


<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  <item>
    <color android:color="@color/splash_background"/>
  </item>
  <item>
    <bitmap
        android:src="@drawable/splash_logo"
        android:tileMode="disabled"
        android:gravity="center"/>
  </item>
</layer-list>

but you can use a layout, in the same way it is used for MainActivity