我有一个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包概述:
有关为何的想法?我非常感谢有关崩溃原因的任何意见。