Android radio background style when choosing

I know how to set the background for my switch. But I don't know what is the best / right way to change the background of the selected switch? Is it possible to do this in xml or do it in code?

Hello

+13
android radio-button background
Jun 05 2018-11-11T00:
source share
3 answers

Just create an XML selector file in a portable folder

checkbox_background.xml

<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:state_checked="true" android:drawable="@color/checkbox_active" /> <item android:state_checked="false" android:drawable="@color/checkbox_inactive" /> </selector> 

And apply this background to your switches

  <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/checkbox_background" /> 
+31
Nov 12
source share

You can define a selector for your switch as described in this answer:

Can I change the radio button icon in the android switch group

0
Jun 05 '11 at 20:10
source share

Using

 android:gravity="center" 

for the switch. This centers the text.

-7
Oct 24 '14 at 2:51
source share



All Articles