Questions tagged [android-switch]

Switch is an android class for a two state toggle switch

From Android Developer Documentation:

A Switch is a two-state toggle switch widget that can select between two options. The user may drag the "thumb" back and forth to choose the selected option, or simply tap to toggle as if it were a checkbox. The text property controls the text displayed in the label for the switch, whereas the off and on text controls the text on the thumb. Similarly, the textAppearance and the related setTypeface() methods control the typeface and style of label text, whereas the switchTextAppearance and the related seSwitchTypeface() methods control that of the thumb.

The Android Developer Guide regarding toggle buttons also states, that

The ToggleButton and Switch controls are subclasses of CompoundButton and function in the same manner, so you can implement their behavior the same way.

201 questions
16
votes
5 answers

Switch button does not show ON and OFF text in Android

I am creating a switch button programmatically. The problem I have is that the button does not show the ON / OFF text. This is the creation code: final RelativeLayout.LayoutParams ll = new RelativeLayout.LayoutParams( …
jstuardo
  • 3,901
  • 14
  • 61
  • 136
16
votes
5 answers

Switch-Button thumb gets skewed?

The thumb for my Switch-button seems to get skewed(for on&off state). There were similar problems on github, but those were for people making libraries to support Switch button in API 4.0- main contains the switch-button, and there is a thumb and…
Zen
  • 2,698
  • 4
  • 28
  • 41
15
votes
4 answers

Change the state of a switch without triggering OnCheckChanged listener

Is there any workaround helps me to programmatically change the state of Switch widget using switch.setChecked(true); without triggering OnCheckedChangedlistener()? switch.setChecked(true); trigger OnCheckedChangedlistener() automatically but I…
Safa
  • 473
  • 5
  • 22
15
votes
6 answers

Android : Required API to use Switch?

I can't insert a Switch in my project because of the following error : View requires API level 14 (current min is 8): But in my project properties, I use Platform 4.1 and API Level 16. So what is wrong?
Rob
  • 15,732
  • 22
  • 69
  • 107
14
votes
5 answers

Android switch custom left-right drawables

I'm trying to create a custom switch like this: What I feel like I need is something like a left/right drawable each in a green/white state, or alternatively a green outline with a drawable for when the choice should be selected. What I don't…
Mike T
  • 4,747
  • 4
  • 32
  • 52
14
votes
6 answers

Switch Track Color

I want to use a Switch and change its Track Color. So in my opinion nothing spectacular. My Switch layout:
Billabong
  • 457
  • 2
  • 8
  • 23
11
votes
4 answers

Unable to change switch color

I'm looking for applying this color to all switches only. But by default, it is taking colorAccent instead of this theme for switch. Device: marshmallow. layout:
AskQ
  • 4,215
  • 7
  • 34
  • 61
11
votes
0 answers

Android: Custom switch: How to make thumb more than 50% of a track without using images

I'm trying to create a custom switch button that would have its thumb about 75% of its track (in width). I don't want to use images, just drawable shapes, styles etc. So far I've done the following: activity_main.xml
Max
  • 179
  • 1
  • 13
11
votes
5 answers

Switch crashes when clicked on Android 5.0

When clicking on a switch in my app in Android 5.0 the app crashes with the logcat shown below. The logcat doesn't reference my code anywhere in it, and this switch has worked fine on all previous versions. The switch appears invisible except for…
William W
  • 1,776
  • 6
  • 21
  • 40
8
votes
3 answers

Custom Android switch track 'animation'

I've created a basic custom Switch, as defined below.
BlitzKraig
  • 418
  • 1
  • 6
  • 17
8
votes
2 answers

Switch control is not working on Dialog in Android version 5.0

I have used below switch in my application.
Pooja
  • 2,417
  • 20
  • 39
7
votes
3 answers

Android Custom Switch

I'm trying to make a custom switch like this: with these properites: text on both sides always shown. different colors for on and off. and these are two problems I faced since the switch only shows the text on the chosen side , and I can't seem…
Outlandish
  • 243
  • 1
  • 2
  • 13
7
votes
2 answers

Write Text on the Track in Switch Button in Android

I am trying to customize Switch button in Android. I have a problem that I want to show ON-OFF text on the Track not on the Thumb as Default by Android. Can we customize this.
FiXiT
  • 769
  • 1
  • 12
  • 27
7
votes
4 answers

Android switches - making thumb height larger than track height, how?

Is there any way to make the height of the thumb of a switch bigger than the track height in Android versions prior to Lollipop ? I am essentially trying to create a material design-like switch widget in Kitkat (and older versions- the problem here…
user1841702
  • 2,683
  • 6
  • 35
  • 53
5
votes
2 answers

Make switch stay same color when on and off

I'm trying to make an Android Switch act as just a selection between two options, so I want to make it so that the switch is the same color when it's 'on' as when it's 'off'. How do I do this?
Jyclop
  • 469
  • 1
  • 6
  • 15
1
2
3
13 14