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
1
vote
1 answer

Lollipop switch with text does not look good

I am trying to have a yes/no switch in Lollipop. The Holo Switch actually does this nice. But this is what it looks like on my device: How can I make the button background scale with it? I tried settings a different background (thumb), but that one…
Boy
  • 7,010
  • 4
  • 54
  • 68
1
vote
3 answers

Android swtich compat icon?

I need to create the switch as the below image I have both on and off images for it. I implemented them as
WISHY
  • 11,067
  • 25
  • 105
  • 197
1
vote
0 answers

Android Graphical Layout unable to render with v7 support widget

The graphical layout is unable to render because of a v7 support widget within my layout XML. I am using the following support widget:
1
vote
2 answers

How to make SwitchCompat not change colors when checked?

This is how it looks like unchecked: and checked: checked clearly doesn't match design, so how can I make it look like unchecked, when it's checked?
Gintas_
  • 4,940
  • 12
  • 44
  • 87
1
vote
1 answer

Not able to use AppCompat v7 switchcompat widget

I want to use the Switchcompat in my application. I added the appcompat v7 support library into my project but when i am trying to use the switchcompat in my xml it is giving me following error : The following classes could not be found: -…
Preeti Wadhwani
  • 305
  • 1
  • 3
  • 15
1
vote
1 answer

How to use SwitchCompat?

I have a ActionBarActivity. In it I create a list by using ListView and ArrayAdapter. In it I try to use SwitchCompat :
1
vote
0 answers

Android SwitchCompat works only on double-tap

I got a problem with SwithCompat, its working only on double tap Im using next layout in recyclerview headerview
dennes544
  • 256
  • 3
  • 18
1
vote
1 answer

Can't find reference to switch compat in custom layout in toolbar

I'm trying to add a switchcompat to the toolbar, the menu item references a custom layout toolbar_switch.xml
Brian
  • 4,328
  • 13
  • 58
  • 103
1
vote
1 answer

SwitchCompat color on Lollipop

I have a SwitchCompat in the action bar (v7.Toolbar) of my activity. I want it be colorStructure when off and colorAccent when on. It works fine on pre-Lollipop, but on Lollipop the activated switch is drawn in a color which I did not define…
1
vote
1 answer

SwitchCompat missing thumb drawable on 4.3 and below

I'm using the SwitchCompat library in my app but it seems to be missing the thumb image on certain devices. (4.2.2, 4.1, 4.3 are the devices i tested on.) Instead it just displays the track with nothing indicating whether the switch is on or off.
user3169791
  • 351
  • 2
  • 3
  • 9
0
votes
0 answers

SwitchCompact: Custom track and thumb being ignored

Currently I am using Android Studio Flamingo version 2022.2.1 Patch 2, using Android 33 emulator. I'm trying to create a simple custom Switch, for that I needed to create a total of 4 XML files: thumb.xml
Sudo Sur
  • 385
  • 4
  • 17
0
votes
0 answers

SwitchCompat cannot adjust track size

Good day, I am having difficulties to adjust the switch compat to the corresponding length. I´ll explain, I want to get to this The "términos de uso" (iv_back) and the uso datos móviles (witch_mobile_data) are an item (part of a recycler) that are…
JaviMar
  • 375
  • 5
  • 18
0
votes
0 answers

customize a toggle switch for Android

I tried to customized a toggle switch and after hours on playing with material, I just gave up and re-used the SwitchCompat
Seb
  • 2,929
  • 4
  • 30
  • 73
0
votes
1 answer

Is there anyway to use switchCompat without resetting while running app in java, Android?

I am having Stopwatch app. I have Switchcompat for different backgrounds on the main layout. When I tap the switch while running the time, it is reset to 00:00:00. Is there any way to use the switch without resetting the timer? Here are some parts…
treewalker
  • 89
  • 1
  • 6
0
votes
1 answer

SwitchCompat text not showing up on action bar

I have an action bar on my app and inside the action bar there is a SwitchCompat widget. I've gotten the widget to show up on the action bar but there is no text beside the switch when I test the app. Here's my menu.xml file