繁体   English   中英

Android.Content.Res.Resources + NotFoundException可绘制com.companyname.mySchool:资源ID为#0x7f02012c的drawable / splash_screen

[英]Android.Content.Res.Resources+NotFoundException Drawable com.companyname.mySchool:drawable/splash_screen with resource ID #0x7f02012c

我正在使用Xamarin Visual Studio for Android应用程序,尽管构建成功,但应用程序引发了异常,以下是我的异常的屏幕截图

虽然我正在寻找解决方案,但找不到相关的解决方案。

在此处输入图片说明

SplashActivity:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.OS;
using Android.Runtime;
using Android.Support.V7.App;
using Android.Views;
using Android.Widget;

namespace MySchool.Droid
{
    [Activity(Label = "MySchool", Icon = "@mipmap/icon", Theme =         "@style/Theme.splash", MainLauncher = true, NoHistory = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
    public class SplashActivity : AppCompatActivity
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
        }

        protected override void OnResume()
        {
            base.OnResume();
            Task startup = new Task(StartUp);
            startup.Start();
        }

        async void StartUp()
        {
            await Task.Delay(100);
            StartActivity(new Intent(Application.Context,     typeof(MainActivity)));
            }

    }
}

主要活动:

using System;

using Android.App;
using Android.Content.PM;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;

namespace MySchool.Droid
{
    [Activity(Label = "myschools", Theme = "@style/MainTheme",     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());
        }
    }
}

Splash_Screen.xml

<?xml version="1.0" encoding="utf-8" ?>
<layer-list xmlns:android="https://schemas.android.com/apk/res/android">
  <item>
    <shape android:shape="rectangle">
      <solid android:color="@color/colorAccent" />
      <padding android:left="0dip"
               android:top="0dip"
               android:right="0dip"
               android:bottom="0dip" />
    </shape>
  </item>
  <item>
    <drawable  android:src="@drawable/myschool"
               android:gravity="center" >
    </drawable>
  </item>
</layer-list>

实际上,我尝试使用我的splash_screen图标使SplashActivity成为主启动器,以便在我的应用程序上线时显示该代码,以下是代码片段,以及顶部的异常屏幕截图。

提前致谢

首先,我没有在OnCreate()看到您的Splash Activity的布局设置:

protected override void OnCreate(Bundle savedInstanceState)
{
    base.OnCreate(savedInstanceState);

    SetContentView(Resource.Layout.Splash_Screen); //This Line is needed
}

这就是Splash_Screen.axml在文件夹Resources\\layout\\Splash_Screen.axml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:foo="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
  <ImageView
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:src="@drawable/splash_background"
      android:scaleType="fitXY" />
  <RelativeLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_gravity="bottom"
      android:paddingBottom="20dp">
    <TextView
        android:id="@+id/lblBottomText"
        android:text="Hello and welcome to stackoverflow"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="@color/black"
        android:textSize="20dp"
        android:gravity="center" />
  </RelativeLayout>
</FrameLayout>

编辑

在您的SplashActivity.cs尝试此代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.OS;
using Android.Runtime;
using Android.Support.V7.App;
using Android.Views;
using Android.Widget;

namespace MySchool.Droid
{
    [Activity(MainLauncher = true, Label = "MySchool", Icon = "@mipmap/icon")]
    public class SplashActivity : AppCompatActivity
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.Splash);

            new Handler().PostDelayed(() =>
            {
                StartActivity(new Intent(this, typeof(MainActivity)));
                Finish();
            }, 2500);
        }
    }
}

然后确保你添加下列文件Splash.axml内部Resources文件夹,里面的layout文件夹MySchool.Droid\\Resources\\layout\\Splash.axml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TextView
        android:id="@+id/lblBottomText"
        android:text="Hello and welcome to stackoverflow"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center" />
</FrameLayout>

然后您应该能够看到Splash屏幕2.5秒钟。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM