Xamarin.Android 啟動頁


  打開軟件的時候相當慢,會有白屏顯示,這樣的用戶體驗效果不好,所以需要增加一個啟動頁來過渡。步驟如下:

第一步:根據自己需求找到一個png圖片,用於啟動展示,放在Drawable 文件夾下,我這里命名為Loading.png。

第二步:在Drawable 文件夾下創建 splashscreen.xml,用於展示Loading.png。

<?xml version="1.0" encoding="utf-8" ?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/loading"
android:gravity="fill"
android:layout_gravity="center"/>

第三步:在Values文件夾下添加 Styles.xml,自定義顯示主題。

<?xml version="1.0" encoding="utf-8" ?>
<resources>
  <style name="Theme.Splash"
    parent="android:Theme.Holo.Light">
    <item name="android:windowBackground">@drawable/loadingscreen</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsTranslucent">false</item>
    <item name="android:windowIsFloating">false</item>
    <item name="android:backgroundDimEnabled">true</item>
  </style>
</resources>

第四步:創建一個LoadingScreen.cs類,其作用是程序開啟第一個調用的Activity

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.Content.PM;

namespace App1
{
    [Activity(MainLauncher = true, NoHistory = true, Theme = "@style/Theme.Splash", ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
    public class SplashScreen : Activity
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            var intent = new Intent(this, typeof(MainActivity));
            StartActivity(intent);
            Finish();
        }
    }
}

第五步:去掉MainActivity.cs類中的“MainLauncher = true”。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM