Xamarin.Forms (Android制作启动画面)

http://blog.csdn.net/zapzqc/article/details/38496117

    Xamarin.Forms 在启动的时候相当慢,必须添加一个启动界面,步骤如下:
1.将启动画面的图片命名为:splash_screen.png,并拷贝到 Resources 文件夹下的相应 Drawable 文件夹中;

   

2.在其中的 Drawable 文件夹下创建 splashscreen.xml ,内容为:
  1. <?xml version="1.0" encoding="utf-8" ?>   
  2. <bitmap xmlns:android="http://schemas.android.com/apk/res/android"   
  3. android:src="@drawable/splash_screen"   
  4. android:gravity="fill"   
  5. android:layout_gravity="center"/>  
 
3.在android项目的 Resources 文件夹下添加“Values”文件夹,创建 Styles.xml,设置其创建内容如下:
  1. <?xml version="1.0" encoding="utf-8" ?>  
  2. <resources>  
  3.   <style name="Theme.Splash"  
  4.     parent="android:Theme.Holo.Light">  
  5.     <item name="android:windowBackground">@drawable/splashscreen</item>  
  6.     <item name="android:windowNoTitle">true</item>  
  7.     <item name="android:windowIsTranslucent">false</item>  
  8.     <item name="android:windowIsFloating">false</item>  
  9.     <item name="android:backgroundDimEnabled">true</item>  
  10.   </style>  
  11. </resources>  

4.在Android项目下创建一个SplashScreen.cs类,内容如下:
[csharp] view plain copy
  1. [Activity(MainLauncher = true, NoHistory = true, Theme = "@style/Theme.Splash",  
  2.    ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]  
  3.    public class SplashScreen : Activity  
  4.    {  
  5.        protected override void OnCreate(Bundle bundle)  
  6.        {  
  7.            base.OnCreate(bundle);  
  8.            var intent = new Intent(this, typeof(MainActivity));  
  9.            StartActivity(intent);  
  10.            Finish();  
  11.        }  
  12.    }  
 
5.去掉MainActivity.cs类中的“MainLauncher = true”。

注意,两个xml文件(包括图片文件)属性中的生成操作必须为“AndroidResource”!

posted @   LuoCore  阅读(1855)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示