必须在主题中指定preferenceTheme,即使在包含它之后也是如此

时间:2017-04-07 21:34:37

标签: c# xml xamarin xamarin.android android-preferences

我有一个MainActivity.cs,它会使SettingsFragment.cs片段Test.axml膨胀。首选项定义位于preference_screen.xml内。我在沮丧时得到了这个错误:

Unhandled Exception:
Java.Lang.IllegalStateException: Must specify preferenceTheme in theme occurred

所以显而易见的原因是styles.xml中没有指定偏好主题。但是,即使在我的样式文件中包含它之后,程序仍然在onCreate() - 方法内停止并出现相同的错误。

<style name="AppTheme" parent="@style/Theme.AppCompat.Light">
  <item name="preferenceTheme">@style/PreferenceThemeOverlay</item>
</style>

这是其他文件:

SettingsFragment.cs

using Android.OS;
using Android.Views;
using Android.Widget;
using SupportFragment = Android.Support.V4.App.Fragment;
using PreferenceTest.Fragments;
using Android.Graphics;
using System.Collections.Generic;
using Android.Support.V4.App;
using Android.Support.Design.Widget;
using System;
using Android.Support.V7.Preferences;

namespace PreferenceTest.Fragments
{
    public class SettingsFragment : PreferenceFragmentCompat 
    {

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

        }

        public override void OnCreatePreferences(Bundle savedInstanceState, string rootKey)
        {
            AddPreferencesFromResource(Resource.Layout.preference_screen);
        }

        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            // return our custom view for this fragment
            View view = inflater.Inflate(Resource.Layout.Test, container, false);


            return view;
        }



    }
}

Test.axml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/home_layout">

</RelativeLayout>

preference_screen.xml

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">

  <PreferenceCategory
      android:key="setting_title_title_category"
      android:title="Title options">

    <CheckBoxPreference
        android:id="@+id/setting_title_show_id"
        android:key="setting_title_show"
        android:title="Show Main Title"
        android:summary="Show/hide MainPage title" />

    <EditTextPreference
        android:key="setting_title_text"
        android:title="Set Main Title"
        android:summary="Change MainPage title"
        android:dialogTitle="Change Title"
        android:dialogMessage="Change title please..."/>

  </PreferenceCategory>
</PreferenceScreen>

NuGet包概述:

  • Xamarin.Android.Support.Animated.Vector.Drawable {23.2.1}
  • Xamarin.Android.Support.Design {23.2.1}
  • Xamarin.Android.Support.v14.Preference {23.2.1}
  • Xamarin.Android.Support.v4 {23.2.1}
  • Xamarin.Android.Support.v7.AppCompat {23.2.1}
  • Xamarin.Android.Support.v7.Preference {23.2.1}
  • Xamarin.Android.Support.v7.RecyclerView {23.2.1}
  • Xamarin.Android.Support.Vector.Drawable {23.2.1}

有关为何的想法?我非常感谢有关崩溃原因的任何意见。

0 个答案:

没有答案