android - Toogle button font color and drawableft selector -
xamarin, android. made selector changes background colors:
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="false"> <shape> <solid android:color="#aaaaac"/> <corners android:radius="6dp" /> <padding android:left="5dp" android:top="5dp" android:right="5dp" android:bottom="5dp" /> </shape> <drawable drawableleft="@drawable/male"/> </item> <item android:state_checked="true"> <shape> <solid android:color="#357fca" /> <corners android:radius="6dp" /> <padding android:left="5dp" android:top="5dp" android:right="5dp" android:bottom="5dp" /> </shape> <drawable drawableleft="@drawable/male_pushed"/> </item> </selector>
besides that, want change drawableft , text colors follows. if - android:state_checked="false"
then
android:textcolor="#000000"
, android:drawableleft="@drawable/male"
if - android:state_checked="true"
android:textcolor="#ffffff"
,
android:drawableleft="@drawable/male_pushed"
how this? thank you
you can't set multiple properties drawableleft
, textcolor
etc using single selector. should create selector each attributes.
create
drawable_left_selector.xml
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="false" android:drawable="@drawable/male"/> <item android:state_checked="true" android:drawable="@drawable/male_pushed"/> </selector>
text_color_selector.xml
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="false" android:color="#000000"/> <item android:state_checked="true" android:color="#ffffff"/> </selector>
toggle_selector.xml
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="false"> <shape> <solid android:color="#aaaaac"/> <corners android:radius="6dp" /> <padding android:left="5dp" android:top="5dp" android:right="5dp" android:bottom="5dp" /> </shape> </item> <item android:state_checked="true"> <shape> <solid android:color="#357fca" /> <corners android:radius="6dp" /> <padding android:left="5dp" android:top="5dp" android:right="5dp" android:bottom="5dp" /> </shape> </item> </selector>
set
togglebutton
<togglebutton android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/toggle_selector" android:drawableleft="@drawable/drawable_left_selector" android:textcolor="@drawable/text_color_selector" />
Comments
Post a Comment