Xamarin forms custom splash screen

痴心易碎 提交于 2020-03-26 03:32:15

问题


On my Splash screen, I want to put the App version for both Android and iOS at the bottom


回答1:


To make a custom Splash Screen, try this out

Create SplashScreen.axml in your resource directory in Droid project

`<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
       android:layout_width="match_parent"
       android:layout_height="match_parent">
         <ImageView
          .
          .PLACE YOUR IMAGE CODE HERE
          .
         />
    <TextView
        android:id="@+id/AppVersion"
        android:text="App-Version - "
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginLeft="40dp"
        android:layout_marginBottom="40dp"
        android:textColor="#FFFFFF"
        android:textSize="12"
        android:background="@android:color/transparent" />
</RelativeLayout>`

Then create cs file for your splash screen in Droid project

    namespace Blue.Test {
    [Activity(Theme = "@android:style/Theme.NoTitleBar", MainLauncher = true, NoHistory = true, ScreenOrientation = ScreenOrientation.Portrait)]    
    public class SplashScreenActivity : Activity {
        protected override void OnCreate(Bundle savedInstanceState) {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.SplashScreen);            
            FindViewById<TextView>(Resource.Id.AppVersion).Text = $"Version {PackageManager.GetPackageInfo(PackageName, 0).VersionName}";            
        }
    }
}

Remember to set MainLauncher = true & NoHistory = true in your assemble




回答2:


Normally, we use drawable resource to create the splash screen. It could not input the text, you could generate static images with the text you are interested in.

The way we used to create the splash screen.

Resource> Drawable> Create splash_background.xml

<?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/pink"
    android:tileMode="disabled"
    android:gravity="center"/>
  </item>
</layer-list>

Resources> values> add style in styles.xml

<style name="MyTheme.Splash" parent="Theme.AppCompat.Light.NoActionBar">
  <item name="android:windowBackground">@drawable/splash_background</item>
</style>

Change Theme in MainActivity.

[Activity(Label = "SplashScreenDemo", Icon = "@mipmap/icon", Theme = "@style/MyTheme.Splash", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]

For more about IOS, you could check the link. https://medium.com/@thesultanster/xamarin-splash-screens-the-right-way-3d206120726d



来源:https://stackoverflow.com/questions/59915394/xamarin-forms-custom-splash-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!