\Resources\drawable\splash_screen.xml : warning XA0101: @(Content) build action is not supported

Lazaro Bodevan 26 Reputation points
2021-07-15T05:27:01.447+00:00

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.
114829-captura-de-tela-2021-07-15-022052.png

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,355 questions
0 comments No comments
{count} vote

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 75,746 Reputation points Microsoft Vendor
    2021-07-15T07:42:08.89+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    Your splash_screen.xml's color set is wrong. it should be <color android:color="@color/splash_background"/> not the <color android:color="@colors/splash_background"/> like following xml.

       <?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>  
    

    And splash_screen.xml and splash_logo.png 's build action is AndroidResource

    114900-image.png

    Best Regards,

    Leon Lu


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.