Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Color in Off state #86

Open
chemickypes opened this issue Feb 27, 2017 · 6 comments
Open

Change Color in Off state #86

chemickypes opened this issue Feb 27, 2017 · 6 comments

Comments

@chemickypes
Copy link

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
Copy link
Author

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
Copy link
Owner

kyleduo commented Feb 27, 2017

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

@chemickypes
Copy link
Author

@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
Copy link
Owner

kyleduo commented Feb 27, 2017 via email

@chemickypes
Copy link
Author

@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
Copy link

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>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants