android-switch

Android - programmatically change the state of a switch without triggering OnCheckChanged listener

☆樱花仙子☆ 提交于 2021-02-17 15:06:55
问题 I'm looking for a method of programmatically changing the state of an Android Switch widget using switch.setChecked(true); without triggering OnCheckedChangedlistener . My first thought was to swap it out for an OnClickListener but as this only registers clicks and you are able to not only click but also slide a Switch then it's not really fit for purpose as if the user was to slide the Switch from off to on then the Switch would actually do nothing as the user is not clicking... If anyone's

Android - programmatically change the state of a switch without triggering OnCheckChanged listener

怎甘沉沦 提交于 2021-02-17 15:04:40
问题 I'm looking for a method of programmatically changing the state of an Android Switch widget using switch.setChecked(true); without triggering OnCheckedChangedlistener . My first thought was to swap it out for an OnClickListener but as this only registers clicks and you are able to not only click but also slide a Switch then it's not really fit for purpose as if the user was to slide the Switch from off to on then the Switch would actually do nothing as the user is not clicking... If anyone's

Custom Android switch track 'animation'

我的未来我决定 提交于 2020-01-01 05:04:17
问题 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 Switch thumb image stretched

ε祈祈猫儿з 提交于 2019-12-25 03:55:32
问题 I need a custom Switch in Android application. I'm using this code: <Switch android:id="@+id/switchmode" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentBottom="true" android:textOn="" android:textOff="" android:switchMinWidth="0dp" android:thumb="@drawable/switch_bg" android:track="@drawable/track_bg" android:layout_marginBottom="20dp" android:layout_marginRight="20dp" /> track_bg file is: <selector

Switch Track Color

六月ゝ 毕业季﹏ 提交于 2019-12-23 08:54:40
问题 I want to use a Switch and change its Track Color. So in my opinion nothing spectacular. My Switch layout: <Switch android:id="@+id/Switch1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:track="@color/gray" android:textOn="@string/on" android:textOff="@string/off" android:text="@string/musiconoff" /> and my color "grey": <color name="gray">#666666</color> My Problem is that the

Switch case in Data Binding

心已入冬 提交于 2019-12-22 09:28:02
问题 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. 回答1: No, as far as I know it is not possible and also would make the xml files really unreadable. I

Android Custom Switch

穿精又带淫゛_ 提交于 2019-12-21 17:36:38
问题 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. 回答1: After researching I found a way that gives me exactly what I needed, this is what I got:

MapView not returning to normal state after clicking toggle switch

☆樱花仙子☆ 提交于 2019-12-20 04:05:14
问题 I'm trying to get my map view to return to the normal style when I flick the switch within my fragment to the the OFF position but it's not working. The following is what occurs during the process that I am facing: Fragment (containg map) and switch appeared Flicked switch to ON position Styled map appeared Flicked switch to OFF position Map doesn't change I tried using mGoogleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); but the map still remains stuck on the styled map view when I flick the

How can I style an Android Switch?

☆樱花仙子☆ 提交于 2019-12-17 02:01:05
问题 The switch widget introduced in API 14 is styled by default with holo theme. I want to style it slightly different, changing its colors and shape a bit for branding reasons. How does one go about this? I know it must be possible, as ive seen the difference between default ICS and Samsung's touchwiz theme I assume I'll need some state drawables, and I've seen a few styles in http://developer.android.com/reference/android/R.styleable.html with Switch_thumb and Switch_track that look like what I

Show/Hide views in RecyclerView on any event in Toolbar

六眼飞鱼酱① 提交于 2019-12-13 03:25:31
问题 I have a Switch button in toolbar and two TextViews in RecyclerView . I want to manage the visibility of one of the TextViews in RecyclerView based on the state of Switch . I have added OnCheckedChangeListener to the Switch and am setting a boolean FLAG to TRUE of FALSE here. This FLAG value is read in onBindViewHolder(-,-) method of the Adapter and I am setting the View visibility to VISIBLE/GONE based on the FLAG . In MainActivity: Switch switchView; private boolean switchFlag; public