【发布时间】:2020-05-11 21:35:17
【问题描述】:
【问题讨论】:
-
为什么不在分片代码上创建一个专门的启动画面?
标签: android ios xamarin.forms xamarin.android xamarin.ios
【问题讨论】:
标签: android ios xamarin.forms xamarin.android xamarin.ios
这就是我在 Xamarin Forms 应用程序中添加启动画面的方式
这是我网站上的一些sample code。
【讨论】:
要制作自定义启动画面,试试这个
在 Droid 项目的资源目录中创建 SplashScreen.axml
`<?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>`
然后在 Droid 项目中为你的启动画面创建 cs 文件
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}";
}
}
}
记得在你的 assemble 中设置MainLauncher = true & NoHistory = true
【讨论】:
通常,我们使用可绘制资源来创建启动画面。无法输入文字,你可以用你感兴趣的文字生成静态图片。
我们用来创建启动画面的方式。
Resource> Drawable> 创建 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> 在styles.xml 中添加样式
<style name="MyTheme.Splash" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">@drawable/splash_background</item>
</style>
在 MainActivity 中更改主题。
[Activity(Label = "SplashScreenDemo", Icon = "@mipmap/icon", Theme = "@style/MyTheme.Splash", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
有关 IOS 的更多信息,您可以查看链接。 https://medium.com/@thesultanster/xamarin-splash-screens-the-right-way-3d206120726d
【讨论】: