打开软件的时候相当慢, 会有白屏显示, 这样的用户体验效果不好, 所以需要增加一个启动页来过渡. 步骤如下:
第一步: 根据自己需求找到一个 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".
来源: http://www.bubuko.com/infodetail-2855101.html