简体   繁体   English

Xamarin Forms Android 充气错误 ZA2F2ED4F8EBC2CBB4C21A29DC40AB61GridViewZ

[英]Xamarin Forms Android Error inflating class MaterialCalendarGridView

I get the following Error message after migrating from FormsApplicationActivity to FormsAppCompatActivity:从 FormsApplicationActivity 迁移到 FormsAppCompatActivity 后,我收到以下错误消息:

Android.Views.InflateException: 'Binary XML file line #31 in com.myapp.app:layout/mtrl_calendar_month_labeled: Binary XML file line #18 in com.myapp.app:layout/mtrl_calendar_month: Error inflating class com.google.android.material.datepicker.MaterialCalendarGridView'

The error happens in the OnCreate at the first line base.OnCreate(savedInstanceState);错误发生在第一行的 OnCreate 中base.OnCreate(savedInstanceState);

My mainactivity looks like this我的主要活动看起来像这样

[Activity(ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation, ScreenOrientation = ScreenOrientation.Portrait, LaunchMode = LaunchMode.SingleTop, MainLauncher = true, Theme = "@style/MyAppTheme")]
    [IntentFilter(new[] { Intent.ActionView},
        DataScheme = "https",
        DataHost =  "MyApp.com",
        AutoVerify = true,
        Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable})]
    [IntentFilter(new[] { Intent.ActionView },
        DataScheme = "http",
        DataHost = "MyApp.com",
        AutoVerify = true,
        Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable })]


    //[Activity(Label = "Muzzillo_v1", MainLauncher = true, Theme = "@style/AppTheme")]
    public class MainActivity : FormsAppCompatActivity, Android.Gms.Tasks.IOnSuccessListener
    {
        static MainActivity instance = null;
        public const string TAG = "MainActivity";
        internal static readonly string CHANNEL_ID = "my_notification_channel";


        public static Context AppContext;

        public static MainActivity CurrentActivity { get { return instance; } }

        IDeviceInstallationService _deviceInstallationService;
        IDeviceInstallationService DeviceInstallationService
    => _deviceInstallationService ??
        (_deviceInstallationService =
        DependencyService.Resolve<IDeviceInstallationService>());

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

            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);

            AppCenter.Start(Constants.AppCenterAndroidKey,
                       typeof(Analytics), typeof(Crashes));

            Xamarin.Essentials.Platform.Init(this, savedInstanceState);

            if (Intent.Extras != null)
            {
                foreach (var key in Intent.Extras.KeySet())
                {
                    if (key != null)
                    {
                        var value = Intent.Extras.GetString(key);
                        Log.Debug(TAG, "Key: {0} Value: {1}", key, value);
                    }
                }
            }

            AppContext = this;
            instance = this;

            DependencyService.Register<IFileSystemAccessService, FileSystemAccessService>();
            DependencyService.Register<IDevicePropertyService, DevicePropertyService>();
            DependencyService.RegisterSingleton<IDeviceInstallationService>(new DeviceInstallationService());

            MR.Gestures.Android.Settings.LicenseKey = "P3CL-CRL5-YJFM-KJ6P-DRFT-DK4N-WRCL-XYP5-JY7Z-92HB-CWQM-5LQA-JNVS";

            if (DeviceInstallationService.NotificationsSupported)
            {
                FirebaseInstanceId.GetInstance(Firebase.FirebaseApp.Instance)
                    .GetInstanceId()
                    .AddOnSuccessListener(this);
            }

            LoadApplication(new App());

            App.Current.NotificationsUpdated += Current_NotificationsUpdated;

            ProcessNotificationActions(Intent);

            try
            {
                System.Diagnostics.Debug.WriteLine("Registering for push notifications ...");
                IsPlayServicesAvailable();
                CreateNotificationChannel();
            }
            catch (Exception ex)
            {
                Logger.Critical(ex);
                System.Diagnostics.Debug.WriteLine("MainActivity :: Error :: {0}", ex.Message);
            }
        }

This is my styles.xml:这是我的 styles.xml:

<?xml version="1.0" encoding="UTF-8"?>
<resources>
    <style name="MyAppTheme" parent="Theme.AppCompat.Light">
        <item name="android:colorPrimary">#ec1a23</item>
        <item name="android:colorPrimaryDark">#dd2c00</item>
        <item name="android:colorAccent">#ff3d00</item>
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
  </style>
    <style name="Theme.Splash" parent="android:Theme">
        <item name="android:windowBackground">@drawable/splashscreen</item>
        <item name="android:windowNoTitle">true</item>
    </style>
    <style name="MyTheme" parent="MyTheme.Base">
    </style>
    <style name="MyTheme.Base" parent="android:Theme.Holo.Light">
        <item name="android:colorPrimary">@color/primary</item>
        <item name="android:colorPrimaryDark">@color/primaryDark</item>
        <item name="android:colorAccent">@color/accent</item>
        <item name="android:colorActivatedHighlight">@color/highlight</item>
        <item name="android:actionMenuTextColor">@color/actionbar_text</item>
    </style>
</resources>

And this the layout.xml:这是布局。xml:

<?xml version="1.0" encoding="utf-8"?>
<Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:minHeight="?android:attr/actionBarSize"
    android:background="?android:attr/colorPrimary"/>

UPDATE更新

I can make the exception go away, by deleting the layout.xml file and using the following values in the styles.xml file: I can make the exception go away, by deleting the layout.xml file and using the following values in the styles.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<resources>
    <style name="MyAppTheme" parent="Theme.MaterialComponents.Light">
        <item name="android:colorPrimary">#ec1a23</item>
        <item name="android:colorPrimaryDark">#dd2c00</item>
        <item name="android:colorAccent">#ff3d00</item>
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
  </style>
    <style name="Theme.Splash" parent="Theme.MaterialComponents.Light">
        <item name="android:windowBackground">@drawable/splashscreen</item>
        <item name="android:windowNoTitle">true</item>
    </style>
</resources>

Any idea how to fix this, without removing layout.xml ?知道如何在不删除layout.xml的情况下解决此问题吗?

I was able to fix the exception, but now my toolbar is completely gone and I created a new stackoverflow post for that problem: Xamarin Forms Android Toolbar missing after migration to Flyout and AppCompat我能够修复异常,但现在我的工具栏完全消失了,我为该问题创建了一个新的 stackoverflow 帖子: Xamarin Forms Android Toolbar 在迁移到 Flyout 应用程序后丢失

The solution for this problem here was to delete the layout.xml file and to use the following values in the styles.xml file:此问题的解决方案是删除layout.xml文件并在styles.xml文件中使用以下值:

<?xml version="1.0" encoding="UTF-8"?>
<resources>
    <style name="MyAppTheme" parent="Theme.MaterialComponents.Light">
        <item name="android:colorPrimary">#ec1a23</item>
        <item name="android:colorPrimaryDark">#dd2c00</item>
        <item name="android:colorAccent">#ff3d00</item>
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
  </style>
    <style name="Theme.Splash" parent="Theme.MaterialComponents.Light">
        <item name="android:windowBackground">@drawable/splashscreen</item>
        <item name="android:windowNoTitle">true</item>
    </style>
</resources>

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

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