Android Preferencefragment In Viewpager
I have a MyPreferenceFragment that inherits from PreferenceFragmentCompat. This fragment resides inside a viewpager. I want the preference screen to have 1 EditTextPreference, 'Nam
Solution 1:
So .. I needed to do something similar, I hope it helps if you still have the problem.
My SettingsFragment:
using Android.OS;
using Android.Views;
using Android.Util;
using Android.Preferences;
using Android.Support.V7.Preferences;
namespaceAprepara.Droid.Activities.Fragments
{
publicclassSettingsFragment : PreferenceFragmentCompat
{
private View _view;
publicoverridevoidOnCreatePreferences(Bundle savedInstanceState, string rootKey)
{
//AddPreferencesFromResource(Resource.Xml.preferences);
}
publicoverridevoidOnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
AddPreferencesFromResource(Resource.Xml.preferences);
}
}
}
In the settings.xml
<?xml version="1.0" encoding="utf-8"?><android.support.v4.view.ViewPagerxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:id="@+id/my_preferences_settings"/>
In the preference xml.
<?xml version="1.0" encoding="utf-8"?><android.support.v7.preference.PreferenceScreenxmlns:android="http://schemas.android.com/apk/res/android"><android.support.v7.preference.PreferenceCategoryandroid:title="Category 1"><android.support.v7.preference.SwitchPreferenceCompatandroid:key="key1"android:title="Switch Preference"android:summary="Switch Summary"android:defaultValue="true" /><android.support.v7.preference.EditTextPreferenceandroid:key="key2"android:title="EditText Preference"android:summary="EditText Summary"android:dialogMessage="Dialog Message"android:defaultValue="Default value" /><android.support.v7.preference.CheckBoxPreferenceandroid:key="key3"android:title="CheckBox Preference"android:summary="CheckBox Summary"android:defaultValue="true"/></android.support.v7.preference.PreferenceCategory></android.support.v7.preference.PreferenceScreen>
Styles.xml
<?xml version="1.0" encoding="utf-8"?><resources>
....
<stylename="AppTheme"parent="Theme.AppCompat.Light.DarkActionBar"><itemname="colorPrimary">@color/ColorActionBar</item><itemname="colorPrimaryDark">@color/ColorActionBar</item><itemname="colorAccent">@color/accent</item><itemname="preferenceTheme">@style/PreferenceThemeOverlay</item></style><stylename="AppTheme.NoActionBar"><itemname="windowActionBar">false</item><itemname="windowNoTitle">true</item><itemname="android:listDivider">@color/background3</item><itemname="preferenceTheme">@style/PreferenceThemeOverlay</item></style><stylename="AppTheme.AppBarOverlay"parent="ThemeOverlay.AppCompat.Dark.ActionBar" /><stylename="AppTheme.PopupOverlay"parent="ThemeOverlay.AppCompat.Light" /></resources>
Folder structure of my project
I'm using the example https://www.codeday.top/2017/07/27/31411.html and https://medium.com/@JakobUlbrich/building-a-settings-screen-for-android-part-1-5959aa49337c
Finally, the result
Post a Comment for "Android Preferencefragment In Viewpager"