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
3
votes
2 answers

Android SwitchCompat not rendering track when in off state

My question is probably best asked visually -- I want a SwitchCompat switch to look the way they do in the Android Settings app: This is off: This is on: But for some reason, my SwitchCompat switch looks like this when off: There is no gray…
esilver
  • 27,713
  • 23
  • 122
  • 168
3
votes
1 answer

Android SwitchCompat style

I tested my app on my new device with android 5.1.1. In my SettingsActivity i have a switch. I already read some posts and changed it to android.support.v7.widget.SwitchCompat but the problem still is the following: On my old device the switch looks…
Oliver U.
  • 336
  • 1
  • 4
  • 14
3
votes
2 answers

Inbox SwitchCompat button

Today I saw the Inbox App. (source: cbsistatic.com) I'd like to know how can I make THAT switch button on the toolbar (left of searchButton). I didn't find references to (Or I don't search a lot). thanks ^^
3
votes
0 answers

SwitchCompat footer view

I tried to add a footer view to my navigation drawer list containing a SwitchCompat. On pre-KitKat devices, the footer doesn't show up at all - following the debugger steps, the view inflates and is added as a footer, but is not drawn at all. Moving…
psyren89
  • 203
  • 1
  • 12
2
votes
2 answers

Android Switch, validating before toggling switch

I have a Switch, or a SwitchCompat rather on my app. When the user clicks or slides the switch I would like to run some code to determine if they should be allowed to. I have tried the setOnCheckedChangeListener and setOnClickListener methods but…
slaw
  • 611
  • 2
  • 7
  • 20
2
votes
0 answers

CheckBoxPreference SwitchCompat missing animation

I have spent more than 10 hours trying to get the animation of the switch to work. I have tried so many things that I don't remember several of the attempts, but I'll explain those that I remember. Code that should work (I think): I use the…
2
votes
0 answers

SwitchCompat showing box outline and background on certain devices

Please take a look at the attached image. This is my XML code:
2
votes
1 answer

android.support.v7.widget.SwitchCompat render error in targetSdkVersion 24 (Android N)

I am using dependencies { compile 'com.android.support:appcompat-v7:24.0.0' } for android { compileSdkVersion 24 buildToolsVersion "23.0.3" minSdkVersion 18 targetSdkVersion 24 } I have an Activity with a theme
2
votes
1 answer

how to customize switch in android?

I want to customize switch as shown in below image. I have tried 'SwitchCompat' but can't customize it as image. Below is code.