Is it possible to change the radio button icon in the android switch group

I want to allow a user of my Android application to set some parameters. This switch is ideal for this situation. However, I do not like the raster buttons.

Can I change the switch icon? For example, is it possible to create my own layout for each line, and in this layout my own icon and change the font, etc.

+88
android radio-button
Aug 26 '10 at 15:11
source share
5 answers

Yes, maybe you need to define your own style for the switches, in res / values ​​/styles.xml:

<?xml version="1.0" encoding="utf-8"?> <resources> <style name="CustomTheme" parent="android:Theme"> <item name="android:radioButtonStyle">@style/RadioButton</item> </style> <style name="RadioButton" parent="@android:style/Widget.CompoundButton.RadioButton"> <item name="android:button">@drawable/radio</item> </style> </resources> 

'radio' here should be an invoice with an excerpt, radio.xml:

  <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="true" android:state_window_focused="false" android:drawable="@drawable/radio_hover" /> <item android:state_checked="false" android:state_window_focused="false" android:drawable="@drawable/radio_normal" /> <item android:state_checked="true" android:state_pressed="true" android:drawable="@drawable/radio_active" /> <item android:state_checked="false" android:state_pressed="true" android:drawable="@drawable/radio_active" /> <item android:state_checked="true" android:state_focused="true" android:drawable="@drawable/radio_hover" /> <item android:state_checked="false" android:state_focused="true" android:drawable="@drawable/radio_normal_off" /> <item android:state_checked="false" android:drawable="@drawable/radio_normal" /> <item android:state_checked="true" android:drawable="@drawable/radio_hover" /> </selector> 

Then apply the special theme to either the whole application or the actions of your choice.

For more information on themes and styles, see http://brainflush.wordpress.com/2009/03/15/understanding-android-themes-and-styles/ , which is a good guide.

+160
Aug 26 '10 at 15:37
source share

You can place a regular image in the radio unit, like a regular button. to do this, create one XML file in a folder with a choice, for example

 <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/sub_screens_aus_hl" android:state_pressed="true"/> <item android:drawable="@drawable/sub_screens_aus" android:state_checked="true"/> <item android:drawable="@drawable/sub_screens_aus" android:state_focused="true" /> <item android:drawable="@drawable/sub_screens_aus_dis" /> </selector> 

Here you can use 3 different images for radio sharing.

and use this file for RadioButton as:

 android:button="@drawable/aus" android:layout_height="120dp" android:layout_width="wrap_content" 
+30
01 Oct '11 at 12:05
source share

An easier way to just change the switch is to simply set the selector to make the right selection.

 <RadioButton ... android:button="@null" android:checked="false" android:drawableRight="@drawable/radio_button_selector" /> 

And the selector:

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

What all

+7
Mar 12 '16 at 12:23
source share

yes .... `from Xml

 android:button="@drawable/yourdrawable" 

and with Java

 myRadioButton.setButtonDrawable(resourceId or Drawable); 

`

+1
Mar 16 '17 at 12:47 on
source share

Here's probably a quick approach,

enter image description here

With the two icons shown above, you should have a RadioGroup something like this

enter image description here

  • change the orientation of RadioGroup to horizontal.
  • for each RadioButton property, try giving an icon for the Button under CompoundButton ,
  • adjust the size and size,
  • and set the Background attribute when checking.
0
Oct 12 '15 at 13:36
source share



All Articles