android-preferences

Default value of Android preference

 ̄綄美尐妖づ 提交于 2019-12-03 06:47:43
问题 How do you get the default value of an Android preference defined in XML? I don't want to repeat the definition of the default value in both the code and the preferences XML. 回答1: You can define default value in resources ( /values/bool.xml ): <resources> <bool name="mypreference_default">true</bool> </resources> Use the value in the preferences.xml : <CheckBoxPreference android:defaultValue="@bool/mypreference_default" android:key="mypreference" android:title="@string/mypreference_title" />

Multi select ListPreference on android

半腔热情 提交于 2019-12-03 06:27:37
Any idea on implementing a multi-select (check boxes) ListPreference on Android? Would I have to extend the ListPreference? Is there any classes already documented to do this? Thanks Multi select ListPreference now comes natively with Android from API level 11 (Honeycomb). http://developer.android.com/reference/android/preference/MultiSelectListPreference.html Because it will be quite a while before devices have Honeycomb or later installed I'd recommend people to stick with the http://blog.350nice.com/wp/archives/240 solution. EDIT: I think at this moment in time (almost 3 years after this

On/Off Toggle Button in Preferences & Action Bar - Ice Cream Sandwich Style

℡╲_俬逩灬. 提交于 2019-12-03 06:12:44
I am referring to the blue ON/OFF styling as seen in the default Android Settings app on ICS phones. It can also be seen here: http://android-developers.blogspot.com/2012/02/android-design-v2-now-with-stencils.html I want to put them in a Preference screen, would I have to use a custom preference widget? Also, is it easy to put toggle buttons in the Action Bar? It seems to be possible since it is done for Wifi Settings in the default Android Settings on ICS, but it is probably a custom menu item? Any help is greatly appreciated. As easy as: My xml-v14/preferences.xml <SwitchPreference android

How to access widgets in a custom DialogPreference with a inflated layout?

蓝咒 提交于 2019-12-03 05:21:22
Im very new to android and Im trying to load/persist values from my customized DialogPreference. Currently, this fails because findViewById returns null. Is the way I (try) to do it correct? How do I get access to my EditText widgets in the code? public class AddressDialogPreference extends DialogPreference { public AddressDialogPreference(Context context, AttributeSet attrs) { super(context, attrs); setDialogLayoutResource(R.layout.address_dialog); } @Override protected void onBindDialogView(View view) { EditText idField = (EditText) view.findViewById(R.id.hostID); EditText ipField =

How can a PreferenceActivity use a custom preference file

一笑奈何 提交于 2019-12-03 01:29:07
My first attempt at preferences was without knowledge of PreferenceActivity . So now I have an app that stores all user preferences in a specific preference file. I want to migrate to using a PreferenceActivity but I also want my users to keep their preferences. Is there a way to tell my PreferenceActivity to use that specific file for all preferences? You could read all the preferences at the beginning of your app, and then store them in the Preferences using Editor e = PreferenceManager.getDefaultSharedPreferences(getBaseContext()).edit(); e.putBoolean("yourPreference", true); e.putString(

How to use EditTextPreference as a masked Password text field?

眉间皱痕 提交于 2019-12-03 00:56:09
I have a very simple question: I have a EditTextPreference dialog which I want to use for getting the user's password and I want it to be masked. How can I do that? Here is a short example using xml: <EditTextPreference android:key="@string/key" android:title="@string/title" android:summary="@string/summary" android:inputType="textPassword" /> Or you can use numberPassword instead of textPassword . android:inputType="numberPassword" doesn't work for me. Eclipse told me, that no String values are allowed for this attribute. So i used following: <EditTextPreference android:key="@string/key"

Which settings file does PreferenceFragment read/write?

ⅰ亾dé卋堺 提交于 2019-12-02 23:03:16
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. Chris You have to manipulate the PreferenceManager of the SettingsFragment . This is what it looks like // Constants //-------------------------------------------------------------------------- private final static String TAG = SettingsFragment.class

Toolbar is hidden in nested PreferenceScreen

扶醉桌前 提交于 2019-12-02 20:42:24
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="defaultValue" android:key="key_global_setting" android:title="Global title" /> </PreferenceCategory>

Default value of Android preference

孤街醉人 提交于 2019-12-02 20:27:06
How do you get the default value of an Android preference defined in XML? I don't want to repeat the definition of the default value in both the code and the preferences XML. Paweł Nadolski You can define default value in resources ( /values/bool.xml ): <resources> <bool name="mypreference_default">true</bool> </resources> Use the value in the preferences.xml : <CheckBoxPreference android:defaultValue="@bool/mypreference_default" android:key="mypreference" android:title="@string/mypreference_title" /> Then use in code: SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(context

Android Preference Fragment Text Color

我与影子孤独终老i 提交于 2019-12-02 19:11:04
I want to change the text color in android preferences fragment. I am currently using a custom theme to change the checkbox image, background, onClick highlighting and it all works great...besides the text color. I don't want to use a default theme, I want to have my own theme so it all looks how I want to but just change the text color, can someone please help. styles.xml <?xml version="1.0" encoding="utf-8"?> <resources xmlns:android="http://schemas.android.com/apk/res/android"> <style name="selectedTextStyle"> <item name="android:textSize">18sp</item> </style> <style name="buttonTextStyle">