android-preferences

PreferenceFragment.findPreference always returns NULL

时光总嘲笑我的痴心妄想 提交于 2019-12-18 04:03:29
问题 I'm currently trying to make a settings menu, that will show a MultiSelectListPreference , to select multiple contacts from your contact list. At this moment, I'm receiving an NullPointerException , when i try to MultiSelectListPreference#setEntryValue(CharSequence[]) If I put the setEntries first, that one throws the same exception. I've put a breakpoint, to see step by step what happens. The variables are filled because they store Strings , they can contain a String "null", so I guess that

PreferenceFragment.findPreference always returns NULL

醉酒当歌 提交于 2019-12-18 04:03:01
问题 I'm currently trying to make a settings menu, that will show a MultiSelectListPreference , to select multiple contacts from your contact list. At this moment, I'm receiving an NullPointerException , when i try to MultiSelectListPreference#setEntryValue(CharSequence[]) If I put the setEntries first, that one throws the same exception. I've put a breakpoint, to see step by step what happens. The variables are filled because they store Strings , they can contain a String "null", so I guess that

set custom font for text in PreferenceScreen

纵然是瞬间 提交于 2019-12-18 01:06:14
问题 My PreferenceActivity looks like: import android.os.Build; import android.os.Bundle; import android.preference.PreferenceActivity; import android.preference.PreferenceFragment; import android.widget.TextView; public class Settings extends PreferenceActivity { @SuppressWarnings("deprecation") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //setContentView(R.layout.about); Typeface timesFont = Typeface.createFromAsset(getAssets(), "fonts/times

set custom font for text in PreferenceScreen

六月ゝ 毕业季﹏ 提交于 2019-12-18 01:05:30
问题 My PreferenceActivity looks like: import android.os.Build; import android.os.Bundle; import android.preference.PreferenceActivity; import android.preference.PreferenceFragment; import android.widget.TextView; public class Settings extends PreferenceActivity { @SuppressWarnings("deprecation") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //setContentView(R.layout.about); Typeface timesFont = Typeface.createFromAsset(getAssets(), "fonts/times

In preferences, select my sound just like with RingtonePreference

耗尽温柔 提交于 2019-12-17 22:16:32
问题 I have sounds in my /raw folder and I would like my user to be able to choose one sound in preferences exactly like RingtonePreference does but only with my sounds. 回答1: Here my RingtonePreference replacement. All system ringtones and your custom ringtones (defined in xml, stored in res/raw) are listed: ExtraRingtonePreference.java package de.almisoft.test; import java.util.Arrays; import java.util.LinkedHashMap; import java.util.Map; import java.util.TreeMap; import de.almisoft.test.R;

New Preference support library incorrect theme at runtime

你离开我真会死。 提交于 2019-12-17 20:38:01
问题 I'm trying to use the new Preference v14 Support library. To give the preferences a material style, I use the following style on my Activity: <style name="PreferenceTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar"> <item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item> </style> That works fine. My problem is that when I add new Preferences at runtime, they get inflated using an old theme. Here's a screenshot of the result: As you can see, the first preference

Android: Preference Fragment with a Navigation Drawer's Fragment

こ雲淡風輕ζ 提交于 2019-12-17 19:39:46
问题 Hi I have an Android app that already uses a Navigation Drawer. My MainActivity extends Fragment Activity and my SettingFragment extends PreferenceFragment Settings Fragment : public class SettingsFragment extends PreferenceFragment { public SettingsFragment() {} @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Load the preferences from an XML resource addPreferencesFromResource(R.xml.prefs); } } and my MainActivity : PreferenceFragment

Android: How to get the time from a TimePicker when it is typed in

左心房为你撑大大i 提交于 2019-12-17 18:09:32
问题 I've got a DialogPreference which implements a simple TimePicker.OnTimeChangedListener (see below). Setting the time by clicking the +/- buttons works great. But I don't know how to save the state of the timepicker when the user typed in the time directly into the textfield. It could be sufficient to access to the current textfield value, so I'd be able to persist it in onDialogClosed. But timePicker.getCurrentHour() won't do it. Please help... public class TimePreference extends

How can I backup SharedPreferences to SD card?

北战南征 提交于 2019-12-17 17:59:32
问题 I saw in a lot of places that it's a problem to copy the SharedPreferences file to the sd card because every manufacturer place it somewhere else. I want to backup on the sd card no matter where is the file located. Is there any way to do this? 回答1: The SharedPreferences interface contains a method called getAll() which returns a map with the key-value pairs. So instead of copying the file itself, I just serialize the map that being returned from this method and then retrieve it back

Why won't Fragment retain state when screen is rotated?

你说的曾经没有我的故事 提交于 2019-12-17 17:30:48
问题 I've been having some trouble getting some custom DialogPreference subclasses inside a PreferenceFragment to remain visible when the screen is rotated. I don't experience this problem when using a PreferenceActivity, so I don't know whether it's an Android bug or a problem with my code, but I'd like someone to confirm whether they are having the same experience. To test this, first create a preference screen containing at least one DialogPreference (it doesn't matter which subclass). Then