MAUI Android Splash/启动页

  MAUI的Splash可以直接在Resources/Splash文件夹下直接更改,参阅官方文档 https://docs.microsoft.com/zh-cn/dotnet/maui/user-interface/images/splashscreen?tabs=ios

  在实际使用中,如果你想自定义初始屏幕,请跟随我的方法来加载。

   一、在Platforms/Android/Resources文件夹下添加drawable文件夹,Platforms/Android/Resources/drawable。

  二、在文件夹上添加你自定义的splash的xml文件,我的我命名为:splash_bachground.xml, URL:Platforms/Android/Resources/drawable/splash_bachground.xml

 

  三、修改Platforms/Android/Resources/values/style.xml 文件,如没有这个文件,则直接添加一个即可,代码参考如下:

 1 <?xml version="1.0" encoding="utf-8" ?>
 2 <resources>
 3 
 4     
 5     <style name="MainTheme" parent="MainTheme.Base">
 6         <!-- colorPrimary is used for the default action bar background -->
 7         <item name="colorPrimary">#66B32E</item>
 8         <!-- colorPrimaryDark is used for the status bar -->
 9         <item name="colorPrimaryDark">#66B32E</item>
10         <!-- colorAccent is used as the default value for colorControlActivated
11        which is used to tint widgets -->
12         <item name="colorAccent">#66B32E</item>
13     </style>
14 
15     <style name="MainTheme.SplashGW" parent="Theme.MaterialComponents.Light.NoActionBar">
16         <item name="android:windowBackground">@drawable/splash_background</item>
17         <item name="colorPrimaryDark">#66B32E</item>
18     </style>
19 
20     <!-- Base theme applied no matter what API -->
21     <style name="MainTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
22         <!--If you are using revision 22.1 please use just windowNoTitle. Without android:-->
23         <item name="windowNoTitle">true</item>
24         <!--We will be using the toolbar so no need to show ActionBar-->
25         <item name="windowActionBar">false</item>
26         <!-- Set theme colors from http://www.google.com/design/spec/style/color.html#color-color-palette -->
27 
28         <!-- You can also set colorControlNormal, colorControlActivated
29        colorControlHighlight and colorSwitchThumbNormal. -->
30         <item name="windowActionModeOverlay">true</item>
31         <item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item>
32         <item name="android:textAppearanceButton">@style/MyTextAppearance.Material.Button</item>
33     </style>
34     <style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
35         <item name="colorAccent">#FFFFFF</item>
36     </style>
37 
38     <style name="MyTextAppearance.Material.Button" parent="@android:style/TextAppearance.Material.Button">
39         <item name="textAllCaps">false</item>
40         <item name="android:textAllCaps">false</item>
41     </style>
42 
43     <declare-styleable name="MaxHeightScrollView">
44         <attr name="maxHeight" format="dimension"/>
45     </declare-styleable>
46 
47     <!-- 自定义仿IOS的AlertDialog的样式 -->
48     <style name="AlertDialogStyle" parent="Theme.AppCompat.Dialog">
49         <item name="android:windowBackground">@android:color/transparent</item>
50         <item name="android:windowContentOverlay">@null</item>
51         <item name="android:windowIsFloating">true</item>
52         <item name="android:windowFrame">@null</item>
53         <item name="android:backgroundDimEnabled">true</item>
54         <item name="android:windowNoTitle">true</item>
55     </style>
56     
57 </resources>
View Code

  四、修改MainActivity的Theme,参考代码如下:

 1 [Activity(Theme = "@style/MainTheme.SplashGW", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
 2 public class MainActivity : MauiAppCompatActivity
 3 {
 4     public static MainActivity Instance { get; private set; }
 5     protected override void OnCreate(Bundle savedInstanceState)
 6     {
 7         Instance = this;
 8         base.OnCreate(savedInstanceState);
 9     }
10 }
View Code

  总共四步,处理完成后启动Android调试即可。

  当前发布时间为MAUI的第一个版本,目前使用iOS还存在问题,后续修改后再发iOS的初始屏幕。

  参考GitHub URL:https://github.com/zuimengaitianya/GLBMaui,喜欢的给个star。

posted @ 2022-08-26 15:42  醉梦ai天涯  阅读(1513)  评论(2编辑  收藏  举报