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

Android Switch Button Custom design

I am developing an app that can post two kinds of questions. to switch views i need a switch button on the TOP. i need help to customize my switch button like following image.
Ronak Makwana
  • 188
  • 2
  • 12
5
votes
3 answers

Null pointer exception on switch widget in kitkat version

I have used switch widget in my application. when I run app on lollipop, its working fine with it. but when I run in kitkat version, its going to crash. xml design:
Sagar Maiyad
  • 12,655
  • 9
  • 63
  • 99
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
2 answers

Trying to programmatically set the state of a SWITCH inside a LISTVIEW after the listview is displayed

So i have a list of alarms and i bind that to the listview, lstAlarms. In my custom ListView layout, i also have a switch, which i want to be set programmatically according to the status of the alarm. I want to do this right after the ListView is…
Vibol
  • 615
  • 1
  • 8
  • 25
5
votes
1 answer

SwitchCompat on pre lollipop devices

I am trying to implement SwitchCompat from AppCompat but it looks different on different version devices. On Lollipop & Froyo it looks good but on Gingerbread to KitKat it doesn't look like a switch. Code:
user3677365
  • 95
  • 2
  • 13
5
votes
2 answers

Switch in adapter for a ListView

I have a ListView with an adapter which layout has a Switch, so every item in the lists has a switch. I want to use this code: mySwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton…
Jorge Ibañez
  • 158
  • 1
  • 1
  • 8
5
votes
3 answers

Styling / coloring the SwitchCompat button in Android Lollipop for Material Design

I have been trying to find resources explaining how I can style the Switch button in the Material Design theme. This link does explain the color values and aesthetic details but doesn't say much on how I can achieve this by setting certain…
FoY
  • 398
  • 1
  • 4
  • 17
4
votes
1 answer

error: style attribute 'android:attr/colorSwitchThumbNormal' is private

I am trying to change the color of "disabled" state in a SwitchCompat. I added this at Styles.xml: