android-preferences

Preference fragment tab adapter

≡放荡痞女 提交于 2020-01-25 03:04:27
问题 I want to build a preference tab for my app but since I have other tabs extending from a regular fragment, I have an incompatible types error, as a PreferenceFragment cannot be converted to Fragment. Here is my Tab Fragment Adapter : public class PagerAdapter extends FragmentStatePagerAdapter { int mNumOfTabs; public PagerAdapter(FragmentManager fm, int NumOfTabs) { super(fm); this.mNumOfTabs = NumOfTabs; } @Override public Fragment getItem(int position) { switch (position) { case 0:

Where to store Android preference keys?

点点圈 提交于 2020-01-20 12:53:48
问题 When I create preference activity I define all preferences in xml file. Every preference has a key defined in this xml. But when I access preference I write: SharedPreferences appPreferences = PreferenceManager.getDefaultSharedPreferences(this); boolean foo_value = appPreferences.getBoolean("foo_key_defined_in_xml", false); Is there any way to avoid referencing "foo_key_defined_in_xml" in hard-coded way? Maybe there is a possibility to reference it in R style way (not to refer to string)? 回答1

Where to store Android preference keys?

怎甘沉沦 提交于 2020-01-20 12:52:32
问题 When I create preference activity I define all preferences in xml file. Every preference has a key defined in this xml. But when I access preference I write: SharedPreferences appPreferences = PreferenceManager.getDefaultSharedPreferences(this); boolean foo_value = appPreferences.getBoolean("foo_key_defined_in_xml", false); Is there any way to avoid referencing "foo_key_defined_in_xml" in hard-coded way? Maybe there is a possibility to reference it in R style way (not to refer to string)? 回答1

PreferenceActivity: getFragmentManager() has been deprecated

非 Y 不嫁゛ 提交于 2020-01-20 06:54:06
问题 when testing a android.preference.PreferenceActivity, I get the following warning: warning: [deprecation] getFragmentManager() in Activity has been deprecated that is how I obtain a handle to the current PreferenceFragment : FragmentManager fm = this.mActivity.getFragmentManager(); this.currentFragment = (PreferenceFragment) fm.getFragments().get(1); using FragmentActivity.getSupportFragmentManager() is obviously not an option. found PreferenceFragmentCompat, which would replace the

PreferenceActivity: getFragmentManager() has been deprecated

故事扮演 提交于 2020-01-20 06:54:05
问题 when testing a android.preference.PreferenceActivity, I get the following warning: warning: [deprecation] getFragmentManager() in Activity has been deprecated that is how I obtain a handle to the current PreferenceFragment : FragmentManager fm = this.mActivity.getFragmentManager(); this.currentFragment = (PreferenceFragment) fm.getFragments().get(1); using FragmentActivity.getSupportFragmentManager() is obviously not an option. found PreferenceFragmentCompat, which would replace the

Accessing another Activity's preferences

一世执手 提交于 2020-01-17 13:41:45
问题 I have a Login Activity which stores credentials in its own SharedPreferences; then I added two getters for reading them, something like public String getUsername() { return getPreferences(MODE_PRIVATE).getString("#username", null); } but this throws a NPE when I call it like this String mUser = (new Login()).getUsername(); It seems that the Activity cannot read its preferences after a simple contructor call, as if it were in some uncompleted state. I read lots of related topics, but wasn't

How to setOnClickListener() to OK button of an EditTextPreference Dialog? [duplicate]

陌路散爱 提交于 2020-01-16 00:53:06
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: how to call the ok button in the EditTextPreference I want to validate the Inputs (enter 6 digits) of an EditTextPreference dialog box. This is how my (relevant) preferences.xml snippet looks like : <!--EditTextPreference--> <com.app.preferences.UpdatePincodePreference android:key="PIN_CODE_PREFERENCE" android:title="@string/pincode_preference_title" android:summary="@string/pincode_preference_summary" android

How to make functioning Preference Screen?

我怕爱的太早我们不能终老 提交于 2020-01-14 06:23:27
问题 I have made a Preference Screen which I want to make function able. Sorry I can't post any Screen Shot of the Preference Screen as I have not gain required Reputation. Here's my PreferenceScreen code: <?xml version="1.0" encoding="utf-8"?> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" > <PreferenceCategory android:title="Notifications"> <RingtonePreference android:summary="Choose a Ringtone" android:title="Notification Ringtone" android:key="ringtonePref" />

Android changing the background color for preference fragment

拈花ヽ惹草 提交于 2020-01-13 07:58:16
问题 I have set a theme for my application, which includes a blue background... However, this made my preference fragment blue too. I want to keep the original "android:Theme.Holo.Light.DarkActionBar". How to do so? thanks! 回答1: Add the following code to your PreferenceFragment implementation: @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = super.onCreateView(inflater, container, savedInstanceState); view.setBackgroundColor

Reset default values of Preference

我只是一个虾纸丫 提交于 2020-01-12 07:28:06
问题 I am using CheckBoxPreference for settings screen. The XML is: <?xml version="1.0" encoding="utf-8"?> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" > <CheckBoxPreference android:key="includeAddress" android:title="Include Address" android:summary="" android:defaultValue="true" /> <CheckBoxPreference android:key="rememberName" android:title="Remeber Name" android:summary="" android:defaultValue="false" /> </PreferenceScreen> I change the values while in the