尝试在Xamarin Forms中添加启动画面时出现错误 - Xamarin Android

3

我正在尝试为我的应用程序创建启动画面。

我正在使用Xamarin forms,并且目前仅在Android上进行测试。

但是,我收到了以下两个错误:

  1. 生成分割''的资源表失败"Failed to generate resource table for split ''".
  2. 严重性Cod'android:windowBackground' with value '@drawble/splashscreen'。

非常感谢任何帮助解决此问题的人。

谢谢。

这是我的styles.xml:

<resources>

 <style name="Theme.splash" parent="android:Theme">
   <item name="android:windowBackground">@drawble/splashscreen</item>
   <item name="android:windowNoTitle">true</item>    
 </style>

 <style name="MainTheme" parent="MainTheme.Base">
 </style>
 <!-- Base theme applied no matter what API -->
 <style name="MainTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
  <!--If you are using revision 22.1 please use just windowNoTitle. Without 
android:-->
<item name="windowNoTitle">true</item>
<!--We will be using the toolbar so no need to show ActionBar-->
<item name="windowActionBar">false</item>
<!-- Set theme colors from 
http://www.google.com/design/spec/style/color.html#color-color-palette -->
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">#2196F3</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">#1976D2</item>
<!-- colorAccent is used as the default value for colorControlActivated
     which is used to tint widgets -->
<item name="colorAccent">#FF4081</item>
<!-- You can also set colorControlNormal, colorControlActivated
     colorControlHighlight and colorSwitchThumbNormal. -->
<item name="windowActionModeOverlay">true</item>

<item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item>
 </style>

<style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">#FF4081</item>
</style>
</resources>

这是我添加到Activity中的代码:

    [Activity(Label = "SplashScreen", MainLauncher=true, NoHistory=true, Theme = "@style/Theme.splash")]
public class SplashScreen : Activity
{
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);

        StartActivity(typeof(MainActivity));
    }
}

这是主要活动:

[Activity(Label = "RegestrationAppComp", Icon = "@drawable/icon", Theme = "@style/MainTheme", MainLauncher = false, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
    protected override void OnCreate(Bundle bundle)
    {
        TabLayoutResource = Resource.Layout.Tabbar;
        ToolbarResource = Resource.Layout.Toolbar;

        base.OnCreate(bundle);

        global::Xamarin.Forms.Forms.Init(this, bundle);
        LoadApplication(new App());
    }
}
2个回答

3
当您创建splashscreen.xml文件时,必须更改其属性。我按照以下步骤操作:
  • 右键单击splashscreen.xml文件,选择属性,窗口将显示在底部。
  • 在“生成操作”字段上,将值更改为“AndroidResource”
  • 在“自定义工具”字段上,编写“MSBuild:UpdateGeneratedFiles”(或从同一文件夹中其他文件上方或从“values / styles.xml”文件中复制已写入的内容)。

1
请在Visual Studio中的drawable文件夹中添加您的图片(在您的情况下,图片文件名为“splashscreen”)。为此,您需要右键单击“Drawable”文件夹->单击“添加现有项”->从您的笔记本电脑/PC驱动器位置选择您的图像,然后单击“添加”...就这样!现在您可以再次构建和部署解决方案。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接