我遵循下面链接上的代码,
https://forums.xamarin.com/discussion/67821/splash-screen-with-text
下面是我的代码
splash.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@color/primary"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_centerHorizontal="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#fff"
android:text="My test"
android:layout_marginLeft="5dp"
android:textSize="18dp"/>
</LinearLayout>
</RelativeLayout>
但出现错误
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #1: invalid drawable tag RelativeLayout
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1124)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1032)
at android.content.res.Resources.loadDrawableForCookie(Resources.java:2469)
... 29 more
Force finishing activity 1 myapp.SplashActivity
OS:棒棒糖,Xamarin Android
更新
飞溅活动
[Activity(Label = "@string/app_name", MainLauncher = true, LaunchMode = Android.Content.PM.LaunchMode.SingleTop, ScreenOrientation = Android.Content.PM.ScreenOrientation.Portrait, Theme = "@style/MySplashTheme")]
public class SplashActivity : AppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
StartActivity(new Intent(this, typeof(ManifestActivity)));
Finish();
}
}
styles.xml
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<style name="MySplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/splash</item>
</style>
</resources>
https://forums.xamarin.com/discussion/67821/splash-screen-with-text
https://forums.xamarin.com/discussion/31091/splash-screen-using-a-layout
Xamarin : Splash screen using a Layout
https://docs.microsoft.com/en-gb/xamarin/android/user-interface/splash-screen
答案 0 :(得分:0)
在您的build.gradle文件中使用以下代码:
android {
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
}
答案 1 :(得分:0)
我执行了您的布局,并且工作正常。
您是否在colors.xml中声明了原色:
<color name="primary">#3F51B5</color>
答案 2 :(得分:0)
如果您想使用android:windowBackground
设置活动的背景,则应将其与可绘制资源一起使用,然后将其设置为活动主题。
或者,如果您想使用layout.xml,只需删除主题(因为它现在不可用)并设置
// set the user interface layout for this activity
// the layout file is defined in the project res/layout/main_activity.xml file
setContentView(R.layout.activity_main)
在这种情况下,您还必须延迟一段时间后进入下一个活动,而在前一种情况下,在加载活动然后触发intent时,windowbackground是可见的,现在加载了布局(即现在是背景),意图很快就会触发,因此需要一些延迟。