Questions tagged [switchcompat]

SwitchCompat is a version of the Switch widget that follows Material Design guideline and available in a support library and so working with Android API Level 7+ (Android 2.1 +)

SwitchCompat is a version of the Switch widget, available through the V7 AppCompat library. This library includes support for material design user interface implementations.

To use a SwitchCompat:

  • Add com.android.support:appcompat-v7:XX.X.X to your gradle file
  • Use <android.support.v7.widget.SwitchCompat ... /> in your layout:

Multiple attributes are available to customize a switch:

  • app:showText: Whether to draw on/off text
  • app:splitTrack: Whether to split the track and leave a gap for the thumb drawable.
  • app:switchMinWidth: Minimum width for the switch component May be a dimension value, which is a floating point number appended with a unit such as "14.5sp".
  • app:switchPadding: Minimum space between the switch and caption text May be a dimension value, which is a floating point number appended with a unit such as "14.5sp".
  • app:switchTextAppearance: TextAppearance style for text displayed on the switch thumb.
  • app:thumbTextPadding: Amount of padding on either side of text within the switch thumb.
  • app:thumbTint: Tint to apply to the thumb drawable.
  • app:thumbTintMode: Blending mode used to apply the thumb tint.
  • app:track: Drawable to use as the "track" that the switch thumb slides within.
  • app:trackTint: Tint to apply to the track.
  • app:trackTintMode: Blending mode used to apply the track tint.
107 questions
154
votes
9 answers

How to change the color of a SwitchCompat from AppCompat library

I have a few switch controls with different colors in my application and to change their colors I used multiple custom drawable selectors. A new android.support.v7.widget.SwitchCompat control was introduced with the release of the AppCompat v21…
Orest
  • 6,548
  • 10
  • 54
  • 84
86
votes
10 answers

onCheckedChanged called automatically

I have a switch in a recyclerview and data is displayed in the recyclerview after retrieving data from DB. When the recyclerview is opened I read DB and if a field in DB is "Y" I enable the switch or else I disable the switch. Now the problem is…
58
votes
10 answers

How to change the track color of a SwitchCompat

I've tried using the following link to change the color of a SwitchCompat: How to change the color of a SwitchCompat Notice the low constrast in my switch: But after changing all relevant color values the track (the brighter grey) of the…
Close Call
  • 653
  • 1
  • 6
  • 18
22
votes
2 answers

How to apply a custom style to SwitchCompat

I would like to apply a custom style to SwitchCompat. Change drawables and text for on and off state. How can I achieve this? I can't find any examples on how this is done. I tried the following in my styles.xml but apparently I'm not using the…
Wirling
  • 4,810
  • 3
  • 48
  • 78
16
votes
3 answers

Change colorControlActivated color programmatically

I have read a few threads regarding the color, but all of them has to set via style.xml. For now I'm using this to determine the color. ' Is it…
JR Tan
  • 1,703
  • 4
  • 17
  • 35
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
12
votes
3 answers

Resource Not Found error res/drawable/abc_switch_thumb_material.xml after adding SwitchCompat in Android App Bundle

I Know this Question has been asked several times i have read them all and have matched all dependencies so that they have same versions but this error only started to happen after adding Switch Compat as you can also see that by going through the…
12
votes
1 answer

Selection Box around android.support.v7.widget.SwitchCompat

I am trying to mimic the new material design switch in my app and the switchcompat works pretty well. The only problem is a grey selection box appears around the switch on touch and really takes away from the clean look. Is this something I can…
Zander B
  • 247
  • 3
  • 15
11
votes
1 answer

How to customize switch in android

I need to implement this type of switch in my app
Solanki Zeel
  • 548
  • 1
  • 7
  • 18
11
votes
2 answers

SwitchCompat gives null pointer exception in RecyclerView

I have following code to use SwitchCompat with RecyclerView. List item layout which SwitchCompat reside in: fragment_notification_settings_item.xml
11
votes
2 answers

SwitchCompat in actionbar, with fragment

I get an error when trying to set SwitchCompat to action bar. Here is my abswitch.xml
9
votes
1 answer

Android: SwitchCompat, padding and colour issues

I am using the android.support.v7.widget.SwitchCompat and i am encountering the following problems My style which includes colorControlActivated does not apply Switch padding using Android namespace and Res-Auto has no effect How do set the thumb…
Ersen Osman
  • 7,067
  • 8
  • 47
  • 80
7
votes
2 answers

SwitchCompat fontfamily won't change

I'm using Android Studio and have a SwitchCompat widget in my main activity. The default fontfamily it had was sans-serif-medium and I changed it to quicksand_light. I also have some TextViews with each of their fontfamily's set to quicksand_light.…
K.R.
  • 446
  • 4
  • 12
7
votes
1 answer

How to shrink SwitchCompat width?

I want to reduce my Switch's width. The current solution in How to change the size of a Switch Widget and How to change Width of Android's Switch track? is not solving my problem. android:switchMinWidth just defined the minWidth, but I want it to be…
Elye
  • 53,639
  • 54
  • 212
  • 474
7
votes
3 answers

Android switchcompat disable on text clicking

I have a SwitchCompat: and i want to prevent clicking on text title. As i click on…
yital9
  • 6,544
  • 15
  • 41
  • 54
1
2 3 4 5 6 7 8