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

How to change Android Toggle/LabeledSwitch border color programmatically?

I am using Android Toggle library by Angad Singh, to create a LabeledSwitch programmatically, everything works but I am not being able to color the border. LabeledSwitch switch = new…
stramin
  • 2,183
  • 3
  • 29
  • 58
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
1 answer

How to programmatically set switch to unchecked depending on the switch in PreferenceActivity?

I have a switch on the Tab in mainActivity and a switch in Preference which should be interconnected. The switch in the settings should set the same position in the second switch on the Tab. The code works to switch on, but doesnt work back (to…
0
votes
3 answers

onClick not work on LinearLayout with child Switch

I've got a custom LinearLayout with a widget Switch and TextView child. I'd like to be able to click the area covered by the LinearLayout, so I set clickable=true to the LinearLayout, but Switch is not triggered. I wanted to trigger on Switch when I…
Victory
  • 1,184
  • 2
  • 11
  • 30
0
votes
2 answers

Problem with Switch buttons on RecyclerView

I'm kinda new to Android developing and I hope you can help me. I have one RecyclerView, with each cardview showing one image, two text views and one switch button. This app is for myself and I wanted to organize my card collection so the switch is…
0
votes
1 answer

How to configure notification for user with specific date then store it in room database

I'm developing a notification for appointment, and I want to store it in my database. I have a class "Notification" and I have the appointment interface. So, what I need is when the switch is checked the notification will be active, and when the day…
0
votes
2 answers

How to implement validation onto a switch statement?

Simple switch statement with the next button as a final case. I want it so the user must select an image in the switch statement before moving on. I have no idea how to write something to stop them user just clicking the next button and moving onto…
0
votes
1 answer

Is it possible to dynamically change the ON color of a Switch widget?

I am building an app where I want to let the user have the option to change up some colors. Here's what the app looks like : https://i.stack.imgur.com/kxeOm.jpg I want the "Aspect" color to determine the "Notifications" Switch's color. I know how to…
hlbak
  • 27
  • 7
0
votes
2 answers

Switching on android switch at 1st pos automatically switches the 10th switch on in recyclerview

I am working on an app in which I fetched some data from a server in recyclerview. My recyclervew list layout contains 3 view [ textview(to display event name), edit icon (to edit names), one Switch to turn on/off the events. After some days of…
0
votes
2 answers

Switch compact Android SharedPreferences is not working

SharedPreferences in the below code does not work as required. Where am I going wrong? The SharedPreferences is saved on click, and the same is values are being retrieved OnCreate and OnResume in my Android activity. Code: mySwitch = (SwitchCompat)…
Mahesh CS
  • 9
  • 6
0
votes
1 answer

Ho do I properly handle TextView bound to Switch on orientation change, in fragment

As the title suggests, how do I avoid the TextView to lose its text after an orientation change? Notice how the TextView is bound to the Switch: the initial text (defined in XML) is OFF (because the Switch is initially in the off state) and, on…
0
votes
1 answer

Android changing the color of switch states

I looked and many of the answers were deprecated for the older version. I was wonder which attribute changes the color of a SwitchCompat widget. I am looking to change both the on and off state colors when on I would like white while off would be…
Patrick Coyne
  • 61
  • 2
  • 6
0
votes
1 answer

Multiple Switch thumb images

In Android, is it possible to have a Switch that can have different images set for the thumb's checked and unchecked states? For example, when a Switch is in the unchecked state, I'd like the thumb to use image_1.png and when the Switch is in the…
0
votes
4 answers

How to synchronize two buttons in two seperate fragments

Is it possible for two (switch) buttons to have synchronized behavior between fragments? i.e: When button A is switched on in fragment A, I want button B's appearance in fragment B to also appear switched on. How would I do that? The end goal is to…
Bread
  • 71
  • 1
  • 13
0
votes
2 answers

How to make costum switch button in Android?

I'm trying to do something like that in Android, is there any way? I searched a lot but with no success. Thank You.
ROM
  • 153
  • 3
  • 16