在初始屏幕上设置文本和图像:无效的可绘制标签相对布局



我按照下面链接上的代码,

https://forums.xamarin.com/discussion/67821/splash-screen-with-text

下面是我的代码,

飞溅.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

操作系统:棒棒糖,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();
}
}

样式.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:使用布局的初始屏幕

https://learn.microsoft.com/en-gb/xamarin/android/user-interface/splash-screen

https://forums.xamarin.com/discussion/119638/splash-screen-using-android-windowbackground-does-goes-behind-statusbar

我执行了您的布局并且工作正常。

您是否在颜色中声明了原色.xml:

<color name="primary">#3F51B5</color>

如果要使用android:windowBackground来设置活动的背景,则应将其与可绘制资源一起使用,然后设置与活动主题相同的内容。

或者,如果您想使用布局.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)

同样在这种情况下,您必须在延迟后意图下一个活动,而在前一种情况下,windowbackground 在加载活动然后触发意图时可见,现在布局已加载(现在是背景(,很快意图触发,因此需要一些延迟。

相关内容

最新更新