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

Switch case with data binding

Previously I had created an interface with two button implemented data binding to have a case when button A clicked then Shows input 1, if button B clicked then show input 1+2. Something similar to selected flight trip (one way or return). the…
Shawn.Y
  • 181
  • 3
  • 14
0
votes
1 answer

Downloadable font not displaying for Switch TextView

I'm using downloadable fonts for an app, and it's working just fine, however when I've tried to apply the font to the TextView of a Switch, my device won't display it and resorts to the default font - it displays the font correctly for TextViews in…
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
1 answer

Start service from recyclerView

My task is a call service in the RecyclerView when user click on switcher. My service is CountDownTimer work on background. And I dont know how call service from my holder. I have error: Non-static method 'startServiceTimer()' cannot be referenced…
0
votes
1 answer

onCheckedChanged Systematically Called Upon Initialising Method

I have a bindView Method which implements setOnCheckedChangeListener. However, upon initializing this Method, the onCheckedChanged Method is systematically called. How could I avoid this? Here is my code: public void bindView(View view, Context…
JF0001
  • 819
  • 7
  • 30
0
votes
1 answer

Switch - how to enable default animation in Android

I have a standard unaltered Switch class on every list item in a RecyclerView (in order to toggle an item on or off). Usually switches in Android have a nice default animation with the switch sliding into position and a small bubble animation…
Dmitri Borohhov
  • 1,513
  • 2
  • 17
  • 33
0
votes
2 answers

How to increase switch widget's thumb size in android?

I am using a switch widget. here is the code
ANUJ GUPTA
  • 905
  • 13
  • 22
0
votes
1 answer

Button can't be called from onCheckedChanged until I click Switch and click it agan to return to default state

In my code I have 2 EditBox and a Switch. When I click on Switch to true it sets visible linear layout that contains one more EditText with imagelinearLayout.setVisibility(View.VISIBLE); On the bottom I have a Button that does calculations of 2…
Nikola C
  • 322
  • 6
  • 22
0
votes
4 answers

Add switch button in Alert Dialog title bar in Android

How to add a switch button in the title bar of alert dialog? As an example see the Wi-Fi options screenshot. As you can see there is a switch toggle button inside the title in Wi-Fi options. Is it possible to create a custom Alert Dialog to add a…
Ali
  • 839
  • 11
  • 21
0
votes
1 answer

How to add switch listener in action bar android?

I am trying to add a listener to my switch in action bar for that I have read a lot of answers about it on StackOverflow but my app is crashing on below point. my main menu xml
Rishabh
  • 34
  • 8
0
votes
0 answers

i want to get status of switch from server. values i get from server is 0 or 1 based on that i have to set position of switch and do the switching

i am using setOncheckListner. when i change switch position to ON i am able to pass value to sever and switch state is changed. when the page refreshes as the values will be loading from server,switch comes to OFF…
0
votes
2 answers

select all option and individual item select recyclerview android

I am implementing a custom recyclerview with switch for item selection. I have a "Select All" option at the right corner of App Bar (top bar). I want to allow user to use Select All option and also allow individual item selection in recyclerview. I…
0
votes
2 answers

Allow switch to toggle only if internet connection is available

I have used a switch in my android code. If internet service is available then only allow toggle else show a toast message. How do I achieve this? I am unable to do so using switch.setOnCheckedChangeListener(). The check is working only if I press…
Aparajita Sinha
  • 514
  • 1
  • 10
  • 21
0
votes
1 answer

Items in different activities not collapsing

I am trying to create a preferences activity but for some reason, my Switch control is not behaving the way that it is supposed to. It prevents the desired itms from collapsing + my app crashes whenever I navigate to the SettingsActivity. I really…
wbk727
  • 8,017
  • 12
  • 61
  • 125
0
votes
0 answers

How to change the color of the switch btn track/thumb when btn is ON/OFF?

How can I create a Switch button in Android Studio (Java) that changes its track/thumb color when its state is on ON (ex. black in ON state, red in OFF state). I already tried to access to the colors in the tack.xml or color.xml but it don't know…