Xamarin.forms Android应用程序以错误开头:Android.Views.InflateException:<超时超过=“ =” getting =“” exception =“” details =“”>

时间:2019-01-30 17:08:47

标签: android .net xamarin xamarin.forms

我正在使用xamarin.forms开发移动应用程序,但是我的Android应用程序根本无法启动,当调用base.OnCreate(bundle时,会出现错误:Android.Views.InflateException: );在MainActivity中

我的Android MainActivity文件:

using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.OS;
using Auth0.OidcClient;

namespace MyApp.Droid
{
    [Activity(
        Theme = "@style/Theme.Splash",
        MainLauncher = true,
        NoHistory = true,
        ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
    public class SplashActivity : Activity
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            System.Threading.Thread.Sleep(3000); //Let's wait awhile...
            StartActivity(typeof(MainActivity));
        }
    }

    [Activity(
        Label = "MyApp",
        Icon = "@drawable/icon",
        Theme = "@style/MyTheme",
        MainLauncher = true,
        ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
    [IntentFilter(
        new[] { Intent.ActionView },
        Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable },
        DataScheme = "....",
        DataHost = "....",
        DataPathPrefix = "....")]
    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());
        }

        protected override void OnNewIntent(Intent intent)
        {
            base.OnNewIntent(intent);

            ActivityMediator.Instance.Send(intent.DataString);
        }
    }
}

我的AndroidManifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="3.0.0" package="...." android:installLocation="auto">
  <uses-sdk android:minSdkVersion="23" android:targetSdkVersion="27" />
  <uses-permission android:name="android.permission.INSTALL_PACKAGES" />
  <uses-permission android:name="android.permission.DELETE_PACKAGES" />
  <uses-permission android:name="android.permission.RESTART_PACKAGES" />
  <uses-permission android:name="android.permission.GET_ACCOUNTS" />
  <uses-permission android:name="android.permission.USE_CREDENTIALS" />
  <uses-permission android:name="android.permission.INTERNET" />
  <application android:label="MyApp" android:icon="@drawable/name">
    <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
  </application>
</manifest>

我的styles.xml文件:

<?xml version="1.0" encoding="utf-8" ?>
<resources>
  <color name="actionBarBackgroundColor">#95C11F</color>
  <color name="actionBarTextColor">#FFFFFF</color>

  <style name="MyTheme" parent="@android:style/Theme.Holo.Light">
    <item name="android:actionBarStyle">@style/MyTheme.ActionBarStyle</item>
  </style>
  <style name="MyTheme.ActionBarStyle" parent="@android:style/Widget.Holo.Light.ActionBar">
    <item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
    <item name="android:background">@color/actionBarBackgroundColor</item>
  </style>
  <style name="MyTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
    <item name="android:textColor">@color/actionBarTextColor</item>
  </style>

  <style name="BaseTheme.ActionBarStyle" parent="@android:style/Widget.Holo.Light.ActionBar">
    <item name="android:colorControlNormal">@color/actionBarTextColor</item>
    //the rest of your codes...
  </style>

  <style name="Theme.Splash"
    parent="android:Theme">
    <item name="android:windowBackground">
      @drawable/Logo_SplashScreen
    </item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsTranslucent">false</item>
    <item name="android:windowIsFloating">false</item>
    <item name="android:backgroundDimEnabled">true</item>
  </style>
</resources>

有人知道为什么我会不断收到此错误吗?

1 个答案:

答案 0 :(得分:0)

我设法弄清楚发生了什么事。事实证明,Styles.xml现在有所不同,我从旧版应用程序复制了它,但是这种风格导致它崩溃。

正确的样式应该是:

<?xml version="1.0" encoding="utf-8" ?>
<resources>
  <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">#95C11F</item>
    <!-- colorPrimaryDark is used for the status bar -->
    <item name="colorPrimaryDark">#95C11F</item>
    <!-- colorAccent is used as the default value for colorControlActivated
         which is used to tint widgets -->
    <item name="colorAccent">#FFFFFF</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">#FFFFFF</item>
  </style>

  <style name="Theme.Splash"
    parent="android:Theme">
    <item name="android:windowBackground">
      @drawable/Logo_SplashScreen
    </item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsTranslucent">false</item>
    <item name="android:windowIsFloating">false</item>
    <item name="android:backgroundDimEnabled">true</item>
  </style>
</resources>