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

How to remove items from listview on switch on in android?

I have an app which contain listview with switch button, what i want when switch gets on i want to remove item from listview, I have tried a lot but cannot able to remove item .Please help. code of adapter:- private LayoutInflater…
Niraj
  • 107
  • 2
  • 14
0
votes
0 answers

Root Layout of screen is blinking when toggle SwitchCompat

Root layout of screen is blinking black on a second when toggle SwitchCompat only on Lollipop devices. Black becomes only root background, child layouts are normal at this moment. Layout contains child SurfaceView and some another layouts…
0
votes
0 answers

Why doesn't the Switch added to tool bar pick up colors from styles.xml?

I am trying to add a switch to the tool bar. It is showing up, but the color of the switch is not getting picked up from styles.xml. What am I doing wrong? Home.java public class Home extends AppCompatActivity { @Override protected void…
sofs1
  • 3,834
  • 11
  • 51
  • 89
0
votes
1 answer

Getting crash while start the activity

java.lang.NullPointerException at android.text.StaticLayout.(StaticLayout.java:59) …
Amit Thaper
  • 2,117
  • 4
  • 26
  • 49
0
votes
1 answer

android.support.v7.widget.SwitchCompat not working in API level 22 and less

I have a simple android.support.v7.widget.SwitchCompat which is shown below
prago
  • 5,225
  • 5
  • 25
  • 27
0
votes
1 answer

Can not reduce size of Switch in android

I have implemented a custom switch (like iOS) in android. It's working perfectly in xhdpi devices (Nexus 4, moto g3). But can't reduce the track width of switch in Nexus S. its too lengthy. custom_switch_thumb
Tijo Joseph
  • 231
  • 2
  • 7
0
votes
0 answers

Change text colour of SwitchCompat

How can I change text colour of SwitchCompat?I am showing On and Off text in SwitchCompat and i want to change text colour to white.
0
votes
1 answer
0
votes
1 answer

Android - SwitchCompat OnCheckedChangeListener action is running every time the activity is started

I have some SwitchCompat in my Activity, I set the OnCheckedChangeListener to one of them but (using SharedPreferences), every time I start the Activity, the action of OnCheckedChangeListener is performed regardless of whether it is on or off (Which…
Lennoard Silva
  • 767
  • 1
  • 8
  • 17
0
votes
1 answer

Not able to use SwitchCompat in android application

We are trying to use SwitchCompat in our android application(Eclipse). We have taken the code and procedure from the below link. Material design When we created XML file for the same, we are getting the following error. The following classes could…
Basati Naveen
  • 323
  • 6
  • 18
0
votes
1 answer

SwitchCompat or Switch not toggling on Toolbar

I have added a android.support.v7.widget.SwitchCompat switch on Toolbar. Here is my code: SwitchCompat layout file toolbar_switch.xml
zackygaurav
  • 4,369
  • 5
  • 26
  • 40
0
votes
1 answer

difference between switch and switchcompat in android?

Can someone please explain the real difference between Switch and SwitchCompat.Can I use both as toggle button. can both support lower versions of android. thanks in advance
Nabeel K
  • 5,938
  • 11
  • 38
  • 68
0
votes
2 answers

Measuring switchCompat throws exception

Here is my code for measuring height of items inside a listview and setting the list view height based on the total height of it's children. I do not have any problems when using any other view. public static void…
AC-OpenSource
  • 346
  • 1
  • 12
-1
votes
1 answer

SwitchCompats are checked incorrectly after Dark/Light Mode recreates the app

I have four switches in my BottomSheetDialogFragment. When I make DarkMode 'On', the app is recreated. The weird thing is that other switches became 'On' even if those were 'Off' before. (The value in SharedPref is 'false' but the Switch shows…
-1
votes
1 answer

Android: Horizontal Alignment of Switchcompat from both sides

I am trying to align android switchcompat on both side whether its checked or unchecked but without success.
JSimo
  • 125
  • 1
  • 6