android-preferences

How can I add my app's custom ringtones in res/raw folder to a ringtonepreference

允我心安 提交于 2019-12-03 15:38:27
I have this RingtonePreference (from Android Studio's default SettingsActivity): pref_notification.xml: <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <RingtonePreference android:dependency="notifications_alarm" android:key="notifications_alarm_ringtone" android:title="@string/pref_title_ringtone" android:ringtoneType="notification|all" android:defaultValue="content://settings/system/notification_sound" /> SettingsActivity.java: private void setupSimplePreferencesScreen() { if (!isSimplePreferences(this)) { return; } // Add 'general' preferences.

OnPreferenceChangeListener for every setting

。_饼干妹妹 提交于 2019-12-03 15:35:18
I know that I can do something like this: Preference pref = findPreference(getString(R.string.pref_vibrate_on_key)); pref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { LogUtil.d("Working!"); return true; } }); But I would like to add a Listener to every preference. I tried doing: SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); sp.registerOnSharedPreferenceChangeListener(new OnSharedPreferenceChangeListener() { @Override public void onSharedPreferenceChanged(

Add up button to PreferenceScreen

假如想象 提交于 2019-12-03 14:04:10
I can't figure out how I would go about implementing an up button in a PreferenceScreen . An up button displays a caret in your action bar next to your app icon that allows you to navigate the app's hierarchy, more info here . I have a Preference Fragment that displays when my main activity is opened and I can get the up button to display by adding this line " getActionBar().setDisplayHomeAsUpEnabled(true);": protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getActionBar().setDisplayHomeAsUpEnabled(true); getFragmentManager().beginTransaction() .replace

How to wrap preference title?

♀尐吖头ヾ 提交于 2019-12-03 13:59:58
In this picture, the title of my Preference does not wrap around its parent. How can I make the title wrap to a new line? Thanks. xml: <CheckBoxPreference android:key="keypref" android:summary="Summary text does wrap around the borders" android:title="The title of this preference is" > </CheckBoxPreference> Ewoks You would need to make custom layout which resembles default (android internal) CheckBoxPreference. In that xml text view of title should be with ellipsize set to Marque, repeat limit indefinite and scrollable set to horizontal. Than you can set layout of CheckBoxPreference with:

What's different between OnPreferenceChangeListener and OnSharedPreferenceChangeListener

烂漫一生 提交于 2019-12-03 12:31:56
I want to get value of a checkboxpreference. which method is suitable for listen to preference? And what's real difference between OnPreferenceChangeListener and OnSharedPreferenceChangeListener ?! UPDATE Why onSharedPreferenceChanged not called? public class Setting extends PreferenceActivity implements OnSharedPreferenceChangeListener // ,OnPreferenceChangeListener { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences);// deprecated warning } @Override public void onSharedPreferenceChanged(

Get view of preference with custom layout

♀尐吖头ヾ 提交于 2019-12-03 12:08:30
I have a preference android:layout gft. I've set the layout in the android:layout property of the preference in the xml file. Now I need to do an initialization of a button in the layout (it's a +1 button). I need to get that button in the onCreate method (it's a +1 button) but when I use findViewById(button_id) , it returns null. Is there some way to get the view of this preference? UPDATE: It seems like the preference isn't created after I add the preference xml, so I get null. Where I can call findViewById so the button is already created? Thanks. Preferences xml: <Preference android:title=

How to get an Android ListPreference defined in Xml whose values are integers?

陌路散爱 提交于 2019-12-03 10:03:18
Is it possible to define a ListPreference in Xml and retrieve the value from SharedPreferences using getInt? Here is my Xml: <ListPreference android:key="@string/prefGestureAccuracyKey" android:title="@string/prefGestureAccuracyTitle" android:summary="@string/prefGestureAccuracyDesc" android:entries="@array/prefNumberAccuracyLabels" android:entryValues="@array/prefNumberAccuracyValues" android:dialogTitle="@string/prefGestureAccuracyDialog" android:persistent="true" android:defaultValue="2" android:shouldDisableView="false" /> And I want to get the value with something like: int val =

Which settings file does PreferenceFragment read/write?

自古美人都是妖i 提交于 2019-12-03 08:56:27
问题 How can I control which file should be used by a PreferencesFragment for reading and writing settings? I can't find anything about that in the docs. If that can't be controlled via code or XML resources, are there any guarantees, what the file is called, so I can open it explicitly using Activity.getSharedPreferences(String name, int mode) Thanks. 回答1: You have to manipulate the PreferenceManager of the SettingsFragment . This is what it looks like // Constants //-----------------------------

[Android]How to get results from intent launched from preference screen?

白昼怎懂夜的黑 提交于 2019-12-03 08:15:05
I need help in geting results back from intent launched from preference screen // Intent preference DevicePref = getPreferenceManager().createPreferenceScreen(this); // Show a Screen with list of Devices Discovered Intent i = new Intent(this,getDevice.class); DevicePref.setIntent(i); DevicePref.setTitle("Select Device"); DevicePref.setSummary(mSelectedDevice); deviceOptionsCat.addPreference(DevicePref); I want user to select device... In preference screeen I show "Select Device" .. when user clicks that, another screen is launched by intent where all devices are listed. User selects the device

Toolbar is hidden in nested PreferenceScreen

蓝咒 提交于 2019-12-03 07:58:37
问题 I use PreferenceFragment in ActionBarActivity from support-v7 library. In the Activity I have Toolbar . Everything goes okay, until I open a nested PreferenceScreen . In the opened screen the Toolbar is hidden. Maybe somebody know a workaround for this issue? Preferences xml-file: <?xml version="1.0" encoding="utf-8"?> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" > <PreferenceCategory android:title="Main category" > <EditTextPreference android:defaultValue=