I have a MainActivity.cs
which inflates a fragment SettingsFragment.cs
with Test.axml
. The preferences definition is inside preference_screen.xml
. I'm gettings this error while deplyoing:
Unhandled Exception:
Java.Lang.IllegalStateException: Must specify preferenceTheme in theme occurred
So the obvious reasons is that there's no preferenceTheme specified in styles.xml
. However, even after including this in my styles-file, the program still stops inside the onCreate()
-method with the same error.
<style name="AppTheme" parent="@style/Theme.AppCompat.Light">
<item name="preferenceTheme">@style/PreferenceThemeOverlay</item>
</style>
Here's the other files:
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>
An overview of the NuGet packages:
- 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}
Any ideas on why? I highly appreciate any input on why it might be crashing.