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

SwitchCompat Unresolved reference - Android Kotlin

I'm using a SwitchCompat in a fragment where I keep getting and Unresolved reference that don't let me compile. I don't know where to look at any more.. I believe I have my gradle files how they are supposed to be but I still suspect is something…
mvqdev
  • 31
  • 6
0
votes
1 answer

NavigationView SwitchCompat button only works when it is selected

In my code I have a SwitchCompat button located in the NavigationView that should store some values in SharedPreferences. The button works, but in order for it to work properly, it must first be selected, ie. you must first click on the text of the…
Stanojkovic
  • 1,612
  • 1
  • 17
  • 24
0
votes
1 answer

SwitchCompat RTL support

Seems like selector file for track attribute is not working properly for RTL. LTR track and thumb. RTL track and thumb. Here thumb is changed properly, but track images are still unchanged as it should display map icon on the…
P.Juni
  • 2,365
  • 14
  • 26
0
votes
0 answers

Adding drawableEnd to a SwitchCompat in Android

I am working on an Android app in which I want to have a SwitchCompat with a drawable shown between the switch text and the switch toggle view as shown below. For that, I thought android:drawableEnd would work fine, but contrary to my expectations,…
Abdul Mateen
  • 1,418
  • 1
  • 14
  • 32
0
votes
0 answers

SwitchCompat won't be unchecked after a fixed time of the day

I am using switchCompat in my android application. I want something like that after 10:40 am, the switch won't be unchecked, if it is checked once before the time. How can I do that?
0
votes
1 answer

SwitchCompat is not working properly with firebase database

I have firebase database in my android project which contains three values: code, email, date. I am using switchcompat for counting present students in the firebase database. When switch will be checked, data will enter into the firebase database…
0
votes
2 answers

How to insert value 1 into a column in sq-lite through switch compact

I want to insert value 1 in the SQLite column when switch compact is clicked in a card view inside recyclerView ..but when I clicked switchCompact getting NullPointeException. enter image description here Thanks in advance .. I am new into Android…
0
votes
1 answer

SwitchCompat OnCheckedChangeListener called on every orientation change of Fragment

I have an activity which hosts a fragment and the problem is that, on every orientation change and only if the switch was in the checked state, the OnCheckedChangeListener is called. How do I solve this problem? Thanks! MainActivity.java: public…
0
votes
2 answers

Switches in listview automatically gets check when scrolled

I know this question is duplicate to this one Switches in listview automatically gets check android when scrolled but the answer doesen't work for me I am stuck at same problem when i scroll through listview switch get check automatically. My logic…
Rohit Chauhan
  • 1,119
  • 1
  • 12
  • 30
0
votes
1 answer

RecyclerView item to affect the value of a TextView outside the RecyclerView

I have an Activity which contains 2 TextView shows a numerical value and there is a RecyclerView below them, the RecyclerView has a TextView with a numerical value and a SwitchCompat, I want if the user turned the SwitchCompat to ON the number in…
0
votes
1 answer

SwitchCompat in ListView to make network call

I have SwitchCompat inside a listView item , I want this SwitchCompat State to be sent to my remote database every time i change it ON/OFF for the specific item, I tried to put this network call in the adapter but i got the Exception:…
0
votes
1 answer

SwitchCompat on RecyclerViewAdapter

I'm using only one SwitchCompat in my RecyclerView adapter. I need position of the clicked item on RecyclerView and it's working fine when I use TextView instead of SwitchCompat. But SwitchCompat have no response and no position returned. Can anyone…
amir dt
  • 83
  • 2
  • 9
0
votes
4 answers

Switch Compat: onCheckedChanged

I'm trying to implement a settings activity in my android app where users can turn on and off the notification mode. To achieve that I'm using Switch Compat. Here is the layout. It's part of my activity layout.
Jovan
  • 306
  • 6
  • 20
0
votes
0 answers

Customized Android SwitchCompat

I am trying to achieve the following (see image below) with CompatSwitch. . The original post was from Android toggle button custom look. But there is no answer for SwitchCompat or ToggleButton (apart from using the image in ToggleButton). So far, I…
0
votes
0 answers

SwitchCompat no longer support API 9

As of Support Library 25.3.0 the SwitchCompat widget requires API 14 and higher. They say it is fixed in 25.3.1 but I am using 25.4.0 and this is not fixed. I have tried to copy the old SwitchCompat.java file to my project but there is methods and…