kyleduo / SwitchButton

A cute widget of Switch Button for you to create beautiful and friendly UI.
4.71k stars 867 forks source link

Change Color in Off state #86

Open chemickypes opened 7 years ago

chemickypes commented 7 years ago

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" />

_selectcolor 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 commented 7 years ago

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!

kyleduo commented 7 years ago

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

chemickypes commented 7 years ago

@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?

kyleduo commented 7 years ago

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 notifications@github.com于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 .

chemickypes commented 7 years ago

@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.

tarasokunev commented 6 years ago

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"?>

`