Questions tagged [switchpreference]
51 questions
14
votes
7 answers
Android AppCompat v21 provides SwitchCompat does not provide SwitchCompatPreference
It seems AppCompat v21 provides SwitchCompat does not provide SwitchCompatPreference.
I know I can use SwitchPreference but it is not visually identical. On Android 4.x; when I use SwitchCompact from v21 on activity interface, it looks like material…

nLL
- 5,662
- 11
- 52
- 87
6
votes
2 answers
New Android 12+ MaterialSwitch and androidx.preference
So i'm updating my apps to fully support Monet and Material You guidelines, and the official site mentions a new design for the switches. I used it, and that's the result:
I have a preference screen using Androidx preferences library, latest…

m.i.n.a.r.
- 922
- 2
- 12
- 28
6
votes
1 answer
Why cant I exchange CheckBoxPreference with SwitchPreference?
I've made a simple PreferenceScreen with multiple Preference Categorys and CheckBoxPreferences.
…

user343037
- 85
- 6
5
votes
1 answer
androidx: SwitchPreference VS SwitchPreferenceCompat
The Androidx Preference library offers, amongst others, two classes for implementing a SwitchPreference in Settings screens:
SwitchPreference
SwitchPreferenceCompat
Both implementations in the AOSP source code at the time of writting this question…

BamsBamx
- 4,139
- 4
- 38
- 63
5
votes
2 answers
SwitchPreferenceCompat: android:switchTextOff / switchTextOn doesn't work
I'm trying to display a switchPreference which allows the user to display the distance according to miles or kms. I'm using the SwitchPreferenceCompat support library. According to the library, I can use the textSwitchOff and textSwitchOn to add…

Simon
- 19,658
- 27
- 149
- 217
4
votes
1 answer
Custom SwitchPreferenceCompat in androidx
I'm trying to change default switch thumb in preference screen to my custom. I've tried different solutions found here but none of them working. My last try was to create a custom layout but the problem is that I can't properly add switch to that…

Надя Ка
- 51
- 5
4
votes
1 answer
SwitchPreference not changing state after setting onPreferenceChangeListener
I have an activity which extends PreferenceActivity and i have a class which extends PreferenceFragment.
After I initiate the switchPreference variable (inside the Fragment) I set OnPreferenceChangeListener to it.
The problem is when I do set a…

Sagi Shchori
- 150
- 9
3
votes
0 answers
Change color of SwitchPreference AndroidX
How can I change the color of a SwitchPreference after migratin to the AndroidX library? After migrating the switches on-color is changed to white, I want them to be blue. I have tried using theme/style/layout but nothing seems to work.
Edit:…

André
- 143
- 1
- 14
3
votes
2 answers
How can I add a background color to an Android SwitchPreference?
I am using a PreferenceFragment to inflate an xml file with a single SwitchPreference. How can I make the background color of that preference including the title of the SwitchPreference to match the image below. I have tried setting the background…

Alex Wilson
- 1,773
- 1
- 12
- 18
3
votes
2 answers
How to change SwitchPreference title when is clicked
I'm working with my PreferenceActivity where I have a SwitchPreference to which I didn't assing a title using android:title="Title" because I'd like to change it whenever the Switch is clicked.
I've tried this way but didn't work. I also searched on…

Pier
- 794
- 1
- 12
- 27
3
votes
2 answers
Android - Disable SwitchPreference from changing state but get click response to launch dialog?
If I disable using setEnabled(false) the switch is (1) set to off and (2) I don't get a response from the OnClickListener to launch a dialog.
Edit: In this case, I don't want the switch to automatically switch from on to off.
Has anyone dealt…

user2892437
- 1,111
- 1
- 14
- 22
3
votes
3 answers
Can't toggle switch in Custom SwitchPreference
I try to get custom switch preference in adroid. Here is my code
switch_widget.xml

user3693265
- 109
- 1
- 9
2
votes
1 answer
How to check the current state of a SwitchPreference?
I have a SwitchPreferenceCompat and I want to say if Switch preference is enabled show Toast(switch preference is enabled) else it disables again shows a Toast(switch preference is disabled)
There were some questions like this but none of them…

Amir
- 333
- 4
- 16
2
votes
1 answer
How do I check the current state of a SwitchPreference?
I have a SwitchPreference in my SettingsFragment.kt that changes the icon and title depending on if it's on or off.
This is the code for that:
notificationsPreference.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue…

Tom Darious
- 434
- 6
- 18
2
votes
1 answer
How to Change SwitchPreference text color when switch is enabled?
See Screenshot
I want to change that text color of 'Enabled' to blue
Here is my…

Sarah Khan
- 836
- 7
- 11