android-switch

Android Custom Switch

China☆狼群 提交于 2019-12-06 04:01:49
I'm trying to make a custom switch like this: with these properites: text on both sides always shown. different colors for on and off. and these are two problems I faced since the switch only shows the text on the chosen side , and I can't seem to find a place where I can specify two different colors? can I achieve this using the regular switch in android studio or must I use some library? Thank you. After researching I found a way that gives me exactly what I needed, this is what I got: in case of anyone looking for a way to do it, this is how: based on this post answer , which worked great

Switch case in Data Binding

大兔子大兔子 提交于 2019-12-06 03:54:18
Is it possible to write switch case with android Data Binding? Suppose i have 3 conditions like value == 1 then print A value == 2 then print B value == 3 then print C Does there any way to do this stuff in xml by using Data Binding? I know we can implement conditional statement like android:visibility="@{age < 13 ? View.GONE : View.VISIBLE}" But here i am searching for switch case statement. No, as far as I know it is not possible and also would make the xml files really unreadable. I think it would be better to implement this in your business logic, not in layout files. This is definitely

Android Switch widget textOn and textOff not working in Lollipop

孤街醉人 提交于 2019-12-04 14:57:07
问题 The behavior of the switch widget changed in Lollipop (5.0). <Switch android:id="@+id/switcher" android:layout_width="wrap_content" android:layout_height="0dp" android:layout_marginBottom="16dp" android:layout_marginRight="8dp" android:layout_marginEnd="8dp" android:layout_toEndOf="@id/another_view" android:layout_toRightOf="@id/another_view" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" android:layout_alignParentBottom="true" android:textOff="@string/disabled"

Switch crashes when clicked on Android 5.0

依然范特西╮ 提交于 2019-12-04 10:49:40
问题 When clicking on a switch in my app in Android 5.0 the app crashes with the logcat shown below. The logcat doesn't reference my code anywhere in it, and this switch has worked fine on all previous versions. The switch appears invisible except for the background color and only crashes once clicked on. After testing, the same thing happens whether I define a setOnCheckedChangeListener function or not. Even if the switch is in the layout but never in the code it will still crash when clicked on.

How to use data binding for Switch onCheckedChageListener event?

烈酒焚心 提交于 2019-12-04 08:54:07
问题 As question indicates, how to bind checked change listener to Switch button in xml ? I am not using recycler view. Just a simple layout. Any help appreciated. 回答1: You can do it with a method reference: <CheckBox android:onCheckedChanged="@{callback::checkedChangedListener}".../> or with a lambda expression if you want to pass different parameters: <CheckBox android:onCheckedChanged="@{() -> callback.checked()}".../> 回答2: Using lambda expression and a Switch : public void onCheckedChanged

Custom Android switch track 'animation'

会有一股神秘感。 提交于 2019-12-03 13:13:00
I've created a basic custom Switch , as defined below. <Switch android:id="@+id/availSwitch" android:layout_width="wrap_content" android:switchMinWidth="110dp" android:layout_height="wrap_content" android:track="@drawable/switch_track" android:thumb="@drawable/thumb"/> The @drawable/thumb is a simple PNG which works fine. The @drawable/switch_track is defined below. @drawable/trackon and @drawable/trackoff are PNG's. <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="false" android:drawable="@drawable/trackoff" /> <item android:state_checked=

How to have a Lollipop switch button

自作多情 提交于 2019-12-03 09:28:58
问题 I want to have the Lollipop style switch button for my app: How could I implement this button so it looks like this also on older versions of android? 回答1: At first set android:targetSdkVersion="22" in your manifest to make your app compatible to Lollipop . NOTE: Color of your switch depends on this <item name="android:colorAccent">@color/accent</item> Create your own theme for your app in styles.xml in Folder values-v21 <?xml version="1.0" encoding="utf-8"?> <resources> <style name="AppTheme

Android Switch widget textOn and textOff not working in Lollipop

血红的双手。 提交于 2019-12-03 09:18:24
The behavior of the switch widget changed in Lollipop (5.0). <Switch android:id="@+id/switcher" android:layout_width="wrap_content" android:layout_height="0dp" android:layout_marginBottom="16dp" android:layout_marginRight="8dp" android:layout_marginEnd="8dp" android:layout_toEndOf="@id/another_view" android:layout_toRightOf="@id/another_view" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" android:layout_alignParentBottom="true" android:textOff="@string/disabled" android:textOn="@string/enabled" android:fontFamily="sans-serif-condensed" /> Rendered switch when

Switch crashes when clicked on Android 5.0

為{幸葍}努か 提交于 2019-12-03 05:57:28
When clicking on a switch in my app in Android 5.0 the app crashes with the logcat shown below. The logcat doesn't reference my code anywhere in it, and this switch has worked fine on all previous versions. The switch appears invisible except for the background color and only crashes once clicked on. After testing, the same thing happens whether I define a setOnCheckedChangeListener function or not. Even if the switch is in the layout but never in the code it will still crash when clicked on. One of the switches in question: <Switch android:layout_width="90dp" android:layout_height="wrap

How to use data binding for Switch onCheckedChageListener event?

独自空忆成欢 提交于 2019-12-03 01:16:51
As question indicates, how to bind checked change listener to Switch button in xml ? I am not using recycler view. Just a simple layout. Any help appreciated. George Mount You can do it with a method reference: <CheckBox android:onCheckedChanged="@{callback::checkedChangedListener}".../> or with a lambda expression if you want to pass different parameters: <CheckBox android:onCheckedChanged="@{() -> callback.checked()}".../> Using lambda expression and a Switch : public void onCheckedChanged(boolean checked) { // implementation } XML file: <android.support.v7.widget.SwitchCompat android