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
6
votes
1 answer

After migration to Androidx SwitchCompat is white

I've migrated my project to AndroidX. My MainActivity extend FragmentActivity my first SwitchCompat looks all white, it doesn't have any color at all when I first time come to that screen. SwitchCompat is white. All other SwitchCompact under it…
lujomim
  • 71
  • 1
  • 5
6
votes
1 answer

Custom switchcompat with different images for states

Developing application with List and Map data presentations. For switching between presentations should be used custom switch with images, like this: How to create such custom switchcompat?
E I
  • 501
  • 4
  • 13
5
votes
2 answers

How to show process status on a switch in android?

In the material design guide there is a section called "Display processing status" where we see a video of a Switch with a progress indicator on the thumb. https://material.io/design/components/selection-controls.html#switches Because a switch…
Daniel Brown
  • 1,134
  • 1
  • 13
  • 27
5
votes
1 answer

SwitchCompat rendering issues on android

I am using android.support.v7.widget.SwitchCompat in one of my layout. My compile sdk version is 25, buildTools version is 25.0.1, and I am using 25.2.0 version for com.android.support:design I have restarted android studio, invalidated caches, did…
Karu
  • 935
  • 2
  • 13
  • 32
5
votes
0 answers

How to change width of SwitchCompat thumb

My question is about Android SwitchCompat. Style that I want to : But my switch's style is : My thumb's width is something wrong. (Please never mind track size) This is my xml code :
Soyeon Kim
  • 608
  • 7
  • 34
5
votes
1 answer

Create own SwitchCompat Preference

Since the appcompat v7 is missing a SwitchCompatPreference it seems like it's necessary to create it by myself. How can this be achieved? I googled a bit and found a tutorial for a DialogPreference. I tried to adopt it for a SwitchCompatPreference…
theknut
  • 2,533
  • 5
  • 26
  • 41
4
votes
2 answers

How to set width and track text in a Switch/SwitchCompat button and achieve this result? (Image and GIF attached)

I need to implement a button in my app like this I used a SwitchCompat button but the closest I arrived was to this point, having two main problems: 1 - The width of the button does not adjust correctly when screen sizes change (drawable gets cut…
4
votes
1 answer

Android toggle textOn/Off prevent reading from Talkback

I have a SwitchCompat as toggle with text on it (HQ/LQ for different qualities of a stream). For users with good sight I think it is obvious what it means. But I have problems finding a good solution how to make it accessible. I have set a…
Eve
  • 1,153
  • 1
  • 15
  • 34
4
votes
1 answer

Android SwitchCompat onCheckedChangeListener doesn't work

This is my code and it doesn't work for me. I use code from this example. Xml -
Artem
  • 4,569
  • 12
  • 44
  • 86
4
votes
2 answers

Show to set text visible in OFF state at SwitchCompat?

Currently my SwitchCompat looks like the image below (the top portion), however I need to have visible text in OFF state. How would I achieve this?
NickUnuchek
  • 11,794
  • 12
  • 98
  • 138
4
votes
1 answer

Android SwitchCompat thumb not aligned

I'm trying to use SwitchCompat in Android Studio, I put this in build.gradle: compile 'com.android.support:appcompat-v7:21.+' but the thumb is not centered with the slider. and this is my xml:
Suxsem
  • 292
  • 2
  • 15
3
votes
5 answers

How to change the font family of SwitchCompat?

I've noticed that the SwitchCompat's font does not seem to change with what I've set in the fontFamily field. I've also tried using styles with custom fontFamily (which works on TextViews) and even the switchTextAppearance field. It does apply on…
Gama the Great
  • 225
  • 4
  • 16
3
votes
0 answers

SwitchCompat animation breaks if another view is updated at the same time

I'm trying to update a TextView (let's call it name) from the SwitchCompat's OnCheckedChanged() method. The problem is that right after I call name.setText(), the animation that moves SwitchCompat's thumb button interrupts and the thumb button just…
ulmaxy
  • 820
  • 2
  • 14
  • 22
3
votes
2 answers

Restore state of toggle button on canceling dialog

I have a toggle button in my activity. When switch is On, it shows enable dialog and switch is Off, it shows disable dialog. ((SwitchCompat) findViewById(R.id.toggleButton)).setOnCheckedChangeListener(new OnCheckedChangeListener() { …
Raj
  • 41
  • 10
3
votes
2 answers

Android Why switchCompat.setChecked(true) not working after back from BackStack

I excute switchCompat.setChecked(true) in the onViewCreated(...) of Fragment.It works well first time but not working after back from the BackStack.The log show that switchCompat.isChecked() is true,but the UI state of SwitchCompat is off.It is so…
zys
  • 1,306
  • 3
  • 18
  • 37