我正在用Xamarin.Forms开发一个应用程序,我正在尝试将启动屏幕插入到我的安卓项目中。
我找到了一些教程,用于创建带有背景颜色和静态png图像的splash屏幕,但我想使用我的svg动画作为启动屏幕。我想我可以遵循一个静态图像教程,只需用svg动画替换png图像,但它没有工作。到目前为止,我的情况如下:
论SplashActivity.cs
[Activity(Label = "SplashActivity", Theme = "@style/Theme.Splash", MainLauncher = true, NoHistory = true)]
public class SplashActivity : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Create your application here
}
protected override void OnResume()
{
base.OnResume();
Task startupWork = new Task(() => { SimulateStartup(); });
startupWork.Start();
}
async void SimulateStartup()
{
await Task.Delay(5000);
StartActivity(new Intent(Application.Context, typeof(MainActivity)));
}
}论MainActivity.cs
// I only changed the MainLauncher property to false
[Activity(Label = "MyApp", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = false, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize )]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
...
}关于styles.xml (在Xamarin.Android项目中):
<style name="Theme.Splash" parent="android:Theme">
<item name="android:windowBackground">@drawable/desenhando5s</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="colorPrimaryDark">#004632</item>
</style>当我运行应用程序时,它只显示一个黑色屏幕作为启动屏幕,然后显示我的登录页面和往常一样。有人能告诉我怎样才能把我的动画设置成飞溅的屏幕吗?
(FYI:万一有人想知道,我用SVGator制作了动画)
发布于 2022-03-28 09:20:29
您可以使用FFImageLoading在SplashActivity中加载svg映像,而不是在styles.xml中设置它。
溅屏:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FFImageLoading.Views.ImageViewAsync
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>代码:
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Create your application here
SetContentView(Resource.Layout.layout5);
var filePath = "check";
var imageView = FindViewById<ImageView>(Resource.Id.imageView);
ImageService.Instance.LoadCompiledResource(filePath).WithCustomDataResolver(new SvgDataResolver(64, 0, true)).Into(imageView);
}
protected override void OnResume()
{
base.OnResume();
Task startupWork = new Task(() => { SimulateStartup(); });
startupWork.Start();
}
async void SimulateStartup()
{
await Task.Delay(5000);
StartActivity(new Intent(Application.Context, typeof(MainActivity)));
}更新:
请检查一下截图。.svg图像位于drawable文件夹中。layout5是布局文件夹中的启动屏幕。

https://stackoverflow.com/questions/71621508
复制相似问题