SwitchButton icon indicating copy to clipboard operation
SwitchButton copied to clipboard

Change Color in Off state

Open chemickypes opened this issue 8 years ago • 6 comments

There is a way to change color in off state?

<com.kyleduo.switchbutton.SwitchButton
	android:id="@+id/sb_tint_color_3"
	style="@style/SwitchButtonStyle"
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	app:kswTintColor="@color/selector_color" />

select_color file is a simple color selector

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="#ffcc0000" android:state_checked="true"/>
    <item android:color="#ff669900" android:state_checked="false" />
</selector>

But I continue to see only On-state color (red in this example) and I don't see off-color (green in this example).

chemickypes avatar Feb 27 '17 15:02 chemickypes

Update: I can use app:kswThumbColor="@color/selector_color" to change color oh Thumb and it's get selector image. However, background color is not generated.

Another way is to define both app:kswThumbColor="@color/selector_color" and app:kswBackColor="@color/selector_color_background"

I'd like can get generated background color!

chemickypes avatar Feb 27 '17 16:02 chemickypes

You need to provide color selector both for thumb and background if you want colors different from the generated by app:kswTintColor.

kyleduo avatar Feb 27 '17 16:02 kyleduo

@kyleduo Yes, I know.

There is possibility to get an app:kswTintColorChecked and app:kswTintColorUnchecked? So, background colors are be calculated from them.

The best situation is get background colors from state of resource passed inapp:kswTintColor. Will it possibile?

chemickypes avatar Feb 27 '17 16:02 chemickypes

Sry, I'm confused that you mean you've set tintColor but there's no change on background?

The tint logic will generate a preset color for background in checked status like this. There maybe a bug if you not see this.

Angelo Moroni [email protected]于2017年2月28日 周二上午12:47写道:

@kyleduo https://github.com/kyleduo Yes, I know.

There is possibility to get an app:kswTintColorChecked and app:kswTintColorUnchecked? So, background colors are be calculated from them.

The best situation is get background colors from state of resource passed inapp:kswTintColor. Will it possibile?

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/kyleduo/SwitchButton/issues/86#issuecomment-282777057, or mute the thread https://github.com/notifications/unsubscribe-auth/AGsaVH42JILkE_7YSu-ZorcewNOYIJdxks5rgv4agaJpZM4MNPRN .

kyleduo avatar Feb 27 '17 17:02 kyleduo

@kyleduo So, setting tint color with a resource including multiple state like this

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="#ffcc0000" android:state_checked="true"/>
    <item android:color="#ff669900" android:state_checked="false" />
</selector>

I can see custom background color of checked state, otherwise (unchecked state) I see grey (in the background) and white (thumb color).

I expected it to generate and set both colors.

chemickypes avatar Feb 27 '17 17:02 chemickypes

This, how it works: app:kswBackColor="@color/switch_color_states" and in res/color/switch_color_states.xml <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="true" android:color="@color/green_go" /> <item android:state_checked="false" android:color="@color/red" /> </selector>

tarasokunev avatar Jan 14 '18 13:01 tarasokunev