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

Why does my SwitchPreference glitch on orientation change?

I have an activity (extends AppCompatActivity) that contains a PreferenceFragment with my app's settings. The first setting is a SwitchPreference to enable or disable notifications, followed by other preferences that depend upon that…
drmercer
  • 430
  • 8
  • 11
0
votes
2 answers

Why Switch button does not show text?

I create a Switch button this way: Switch sw = new Switch(activity); final RelativeLayout.LayoutParams ll = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); …
jstuardo
  • 3,901
  • 14
  • 61
  • 136
0
votes
1 answer

What does the Android Design guide say about expanding/collapsing ListView items depending on Switch

I have a settings oriented application for both Android and iOS and I'm currently implementing a new feature. In my iOS application, I have a List of different settings and among them is a switch. When the switch is OFF, some list rows (or none)…
Joakim
  • 3,224
  • 3
  • 29
  • 53
0
votes
0 answers

NullPointerException: 'void android.widget.Switch.setOnCheckedChangeListener

I am trying to reference my switch in my toolbar, but I get null pointer exception. I am guessing that I am referencing it wrong. I have experimented quite a lot and could not figure out what is actually wrong. This is my switch layout…
Georgi Koemdzhiev
  • 11,421
  • 18
  • 62
  • 126
0
votes
1 answer

Unable to change switch state from async task

I need to change the state of the switch from inside an async task. I have set an onClickListner() on the switch in my custom adapter and I am passing its reference to the async task. In my async task I trying to update the state of the switch using…
aries
  • 849
  • 3
  • 11
  • 24
0
votes
1 answer

Styling the custom switch in android

I am trying to create a listview with switches. It is working; but not as how i expected it to be. The text ON/OFF is written inside the circle(slider) and not behind it which looks awkward. I cannot find a way on how to put the text behind the…
0
votes
3 answers

Unable to set relativelayout to invisible when activity starts gives NullPointerException

I have a layout where i have a switch and RelativeLayout which contains 2 Image buttons. By default switch remains in the off state. What i want is when the activity loads i want to set the relative layout to b invisible and if the switch is set in…
user2205230
  • 173
  • 1
  • 2
  • 16
0
votes
0 answers

switch button with mysql update function

I am programming an app where the user can switch a toggle to "Ja" (engl. Yes) and "Nein" (engl. No) to start an activity (Training/Spiel). The layout works fine, the switch position gets saved when leaving activity or app. But how can I implement a…
0
votes
1 answer

Android Switch's Method not Executing when Dragged

I have a switch in one of my activities and when the user interacts with it in any way a method called onSwitchClick should be executed. Currently, the function executes when the switch is tapped (both from the on and off positions), but never when…
HSM95
  • 21
  • 2
0
votes
1 answer

How to keep the switch widget in OFF position after closing the application

I am trying to implement the switch widget in Android. However whenever I set the switch to 'OFF' position and I close and re-open my application, it again sets itself to 'ON' value. How can I make it set itself according to the user.
TechFrk
  • 185
  • 2
  • 2
  • 15
0
votes
0 answers

Switch bar is not visible when inside List View, Lollipop only

In the settings page of my app, I am allowing users to turn on or off certain features. I am doing that by using a list view containing a title and switch toggle in each row. When in list view, Lollipop uses a different switch design, and when you…
0
votes
2 answers

Change Android Switch widget height programmatically

I'm using the following code to programmatically create a switch: Switch s = new Switch(mActivity); s.setText(text); s.setBackground(selectorDrawable); …
user1300214
0
votes
4 answers

Vertically center two switches

I want to center two switches as I did with the textviews but I've tried all the possible options without success. This is a brief version of the code:
David
  • 503
  • 3
  • 7
  • 18
0
votes
1 answer

setting switch view state to checked based on database value android

i have just started learning android today, and so far i am going good, but getting an issue while changing the state of switch view dynamically. i have given a option in setting to check updates, so that user can on or off it as per their…
Mohammed Sufian
  • 1,743
  • 6
  • 35
  • 62
0
votes
2 answers

Switch button always checked (on) when starting the actvitity (android application)

Im making an application where users are able to enable/disable the vibration of the phone. For this, I put a switch. Here is my code: public class settings extends Activity { public static boolean vibrationOnOff; @Override …
Simple
  • 23
  • 2
  • 8