Xamarin.Forms 启动页面的设置

Xamarin.Forms 启动页面的设置

Step1:

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

Step2:

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.Content.PM;


namespace KASFApp.Droid
{
    [Activity(MainLauncher = true, NoHistory = true, Theme = "@style/MainTheme",  
   ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)] 

    class SplashScreen : Activity
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            var intent = new Intent(this, typeof(MainActivity));
            StartActivity(intent);
            Finish();
        } 


    }
}

Step3: MainActivity   去掉:MainLauncher = true, 


namespace KASFApp.Droid
{
    [Activity(Label = "KASFApp", Icon = "@mipmap/icon", Theme = "@style/MainTheme",   ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize )]
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
            LoadApplication(new App());
        }
        public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
        {
            Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);

            base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
        }
    }
}

上一篇:dotnet 在 UOS 国产系统上使用 Xamarin Forms 创建 xaml 界面的 GTK 应用


下一篇:Xamarin多层布局AbsoluteLayout