Xml 如何在Xamarin表单中的图层列表中添加splashscreen文本
] 到目前为止,我已经能够添加的标志,但我需要添加的文字,我怎么做呢 以下是我在xamarin表单中的splash.xml代码:Xml 如何在Xamarin表单中的图层列表中添加splashscreen文本,xml,xamarin.forms,xamarin.android,Xml,Xamarin.forms,Xamarin.android,] 到目前为止,我已经能够添加的标志,但我需要添加的文字,我怎么做呢 以下是我在xamarin表单中的splash.xml代码: <?xml version="1.0" encoding="utf-8" ?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <color android:color="@color/c
<?xml version="1.0" encoding="utf-8" ?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<color android:color="@color/colorBlack"/>
</item>
<item>
<bitmap
android:src="@drawable/ic_logo"
android:tileMode="disabled"
android:gravity="center"/>
</item>
</layer-list>
默认屏幕不支持添加文本 解决这个问题的一个快速方法是
在图像中包含这些版本信息
另一种方法是创建一个代表启动屏幕的活动
。然后在创建启动活动时,启动一个持续时间为3秒的计时器。当这3秒钟过去后,您只需启动应用程序的主要活动
splash活动的布局
:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:background="#fff"
android:id="@+id/splashview">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src = "@drawable/splash_logo"
/>
<TextView
android:id="@+id/txtAppVersion"
android:text="test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="30dp"
android:layout_marginBottom="30dp"
android:textColor="#000"
android:textSize="24sp"
android:gravity= "bottom"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
和代码隐藏:
[Activity(Theme = "@style/MyTheme.Splash", MainLauncher =true,NoHistory = true)]
public class SplashActivity : AppCompatActivity
{
static readonly string TAG = "X:" + typeof (SplashActivity).Name;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.Splash);
FindViewById<TextView>(Resource.Id.txtAppVersion).Text = $"Version {PackageManager.GetPackageInfo(PackageName, 0).VersionName}";
}
// Launches the startup task
protected override void OnResume()
{
base.OnResume();
Task startupWork = new Task(() => { SimulateStartup(); });
startupWork.Start();
}
// Prevent the back button from canceling the startup process
public override void OnBackPressed() { }
// Simulates background work that happens behind the splash screen
async void SimulateStartup()
{
Log.Debug(TAG, "Performing some startup work that takes a bit of time.");
await Task.Delay(5000); // Simulate a bit of startup work.
Log.Debug(TAG, "Startup work is finished - starting MainActivity.");
StartActivity(new Intent(Application.Context, typeof(MainActivity)));
}
}
[活动(主题=“@style/MyTheme.Splash”,MainLauncher=true,NoHistory=true)]
公共课堂活动:AppCompativeActivity
{
静态只读字符串TAG=“X:”+typeof(SplashActivity).Name;
创建时受保护的覆盖无效(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.Splash);
findviewbyd(Resource.Id.txtAppVersion).Text=$“版本{PackageManager.GetPackageInfo(PackageName,0.VersionName}”;
}
//启动启动任务
受保护的覆盖void OnResume()
{
base.OnResume();
任务startupWork=新任务(()=>{SimulateStartup();});
startupWork.Start();
}
//防止“后退”按钮取消启动过程
public override void OnBackPressed(){}
//模拟初始屏幕后面发生的背景工作
异步void SimulateStartup()
{
Debug(标记为“执行一些需要花费一些时间的启动工作”);
等待任务。延迟(5000);//模拟一些启动工作。
调试(标记“启动工作完成-启动MainActivity”);
StartActivity(新意图(Application.Context、typeof(MainActivity));
}
}
我上传了一个示例项目,您可以查看。它与InHirting Activity类一起工作,而不是AppCompatActivity