Questions tagged [android-preferences]
1916 questions
63
votes
7 answers
Where to store Android preference keys?
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 =…

pixel
- 24,905
- 36
- 149
- 251
61
votes
11 answers
How to set the Default Value of a ListPreference
i need to set the defult value for a ListPreference when the Activity starts.
I've tried with ListPreference.setDefaultvalue("value"); but it makes the firts Entry of the List as default. I need it because i must check a condition and set as default…

Gnufabio
- 1,505
- 4
- 16
- 26
61
votes
2 answers
Single page PreferenceActivity w/no headers/fragments?
I'm trying to accomplish something that I think is quite easy, but I'm baffled on how to accomplish it using the PreferenceActivity class and the xml preference-header tag.
When the user taps the app settings icon I would like them to be presented…

Billbris
- 703
- 1
- 6
- 10
60
votes
5 answers
Android: Creating custom preference
Is it possible to create an individual preference in an PreferenceScreen?
I would like to code color settings like that:
I know that choosing the color is easy realizable with the ListPreference, but it would be awesome with that kind of…

Jonas
- 1,432
- 3
- 20
- 27
50
votes
10 answers
Best option to store username and password in android app
I am developing an Android app where the user needs to sign in to perform operations. But mostly on an android handset, people use "Keep me signed in", In that case, I'll have to maintain the value of Username and Password within my app. Should I…

Saurabh Agrawal
- 1,355
- 3
- 17
- 33
50
votes
3 answers
Initialize preferences from XML in the main Activity
My problem is that when I start application and user didn't open my PreferenceActivity so when I retrieve them don't get any default values defined in my preference.xml file.
preference.xml file:

pixel
- 24,905
- 36
- 149
- 251
49
votes
6 answers
How to use EditTextPreference as a masked Password text field?
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?

Avi Shukron
- 6,088
- 8
- 50
- 84
49
votes
4 answers
Non Deprecated findPreference() Method? - Android
I want to detect when a Preference contained in a ListView gets clicked, so that I can launch an intent to manage that selection.
I would have done like this in my layout XML file:

Matteo
- 7,924
- 24
- 84
- 129
47
votes
8 answers
How to open or simulate a click on an android Preference, created with XML, programmatically?
I've an android application with preferences declared in XML, loaded with addPreferencesFromResource. The user can open preferences, click on each item and edit them, all works.
One preference I have is:

Markus
- 5,667
- 4
- 48
- 64
47
votes
4 answers
When to use CheckBox and when Switch
Can anyone can tell me when to use Checkbox and when Switch?
I mean, what is the real login difference between the two in the context of a PreferenceActivity?
For example, will you change the next section to Checkboxes? It's part of a set, but using…

David
- 37,109
- 32
- 120
- 141
45
votes
13 answers
How to change text color of preference category in Android?
The textColor attribute isn't working. Here's my XML:
Any ideas?

Michael Eilers Smith
- 8,466
- 20
- 71
- 106
44
votes
3 answers
Android - How Do I Set A Preference In Code
I have an Android application in which I have my preferences in an XML file, which works fine. I now want to set one of the preferences using code instead of displaying the entire preference screen, how would I go about doing this?
stonedonkey
44
votes
3 answers
Dynamic ListPreference in android
How to generate dynamic listPreference in android?
I want to get all wifi access points and make a list using in preference Activity(i.e. make a list using listpreference).
How to do this?

kkk
- 441
- 1
- 4
- 3
44
votes
2 answers
How do you create Preference Activity and Preference Fragment on Android?
As I was following an old tutorial (Créez des applications pour Android -> openclassroom) I got stuck on this deprecated method addPreferencesFromResource(int id) from the PreferenceActivity class.
So my question is :
What is the new way of…

WannaGetHigh
- 3,826
- 4
- 23
- 31
43
votes
1 answer
What's the maximum size for an Android shared preference value?
I fully appreciate dumping lots of data into the preferences is totally inappropriate, but my requirement is not that great, but large enough (potentially 500-5000 bytes) where I've no idea whether it's appropriate or not. The docs do not…

Ollie C
- 28,313
- 34
- 134
- 217