Hello everyone!
I'm new at Xamarin Forms and I'm trying to create an Android Splash Screen. I followed all the steps from the Xamarin Documentation, tried some tutorials, and nothing resolved this issue:
\Resources\drawable\splash_screen.xml : warning XA0101: @(Content) build action is not supported
I installed both Xamarin.Android.Support.v4 and Xamarin.Android.Support.v7.AppCompat, set the Build Actions to None in AndroidManifest and in AssembyInfo, added a file called splash_screen.xml inside Android/Resources/drawable, also added the splash logo called "exercise.png" inside of this same folder, added a new style inside styles.xml, added the color inside colors.xml, and finally created the SplashActivity setting MainLaucher as true and the MainActivity.cs MainLauncher as false.
Here is the code.
->splash_screen.xml
<?xml version="1.0" encoding="utf-8" ?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<color android:color="@colors/splash_background"/>
</item>
<item>
<bitmap
android:src="@drawable/exercise"
android:tileMode="disabled"
android:gravity="center"/>
</item>
</layer-list
-------------------
->styles.xml
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<style name="MainTheme" parent="MainTheme.Base">
</style>
<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>
----------------------
-> colors
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="splash_background">#FFFFFF</color>
<color name="launcher_background">#FFFFFF</color>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>
-------------------------
->SplashActivity.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Util;
using Android.Views;
using Android.Widget;
using KalTrack.Droid;
namespace SplashScreenExemplo.Droid {
[Activity(Theme = "@style/MyTheme.Splash", MainLauncher = true, NoHistory = true)]
public class SplashActivity : Activity {
static readonly string TAG = "X:" + typeof(SplashActivity).Name;
public override void OnCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
base.OnCreate(savedInstanceState, persistentState);
Log.Debug(TAG, "SplashActivity.OnCreate");
}
// Launches the startup task
protected override void OnResume() {
base.OnResume();
Task startupWork = new Task(() => { SimulateStartup(); });
startupWork.Start();
}
// Prevent the back button from canceling the startup process
public override void OnBackPressed() { }
// Simulates background work that happens behind the splash screen
async void SimulateStartup() {
Log.Debug(TAG, "Performing some startup work that takes a bit of time.");
await Task.Delay(2000);
Log.Debug(TAG, "Startup work is finished - starting MainActivity.");
StartActivity(new Intent(Application.Context, typeof(MainActivity)));
}
}
}
One issue that I found out is that if I change the xml file to a png file in android:windowBackground, it works, but the image is completely streched along the screen. Also, if I press Ctrl+Space in this field, it does not show the splash_screen, but only the .png files.
And finally, these are the errors I'm having.