Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am wanting to allow the user of my android application the ability to set some parameters. The radio button is ideal for this situation. However, I don't like the radio buttons are rendered.

Is it possible to change the radio button icon? For example, is it possible to create a custom layout for each row and in that layout reference my own icon and change the font et al.

like image 478
yamspog Avatar asked Aug 26 '10 15:08

yamspog


People also ask

What is the difference between radio button and RadioGroup?

In Android, RadioButton are mainly used together in a RadioGroup. In RadioGroup checking the one radio button out of several radio button added in it will automatically unchecked all the others. It means at one time we can checked only one radio button from a group of radio buttons which belong to same radio group.

How do I change the color of a radio button circle?

Just use the android:buttonTint="@color/colorPrimary" attribute on the <RadioButton> tag. Show activity on this post. to the colour you want.

How do I add radio buttons to my RadioGroup?

List<String> list = new ArrayList<String>(); list. add("one"); list. add("two"); list. add("three"); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.

Why is RadioGroup used for radio button controls in android?

To create each radio button option, create a RadioButton in your layout. However, because radio buttons are mutually exclusive, you must group them together inside a RadioGroup . By grouping them together, the system ensures that only one radio button can be selected at a time.


2 Answers

Yes that's possible you have to define your own style for radio buttons, at 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 a stateful drawable, 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 just apply the Custom theme either to whole app or to activities of your choice.

For more info about themes and styles look at http://brainflush.wordpress.com/2009/03/15/understanding-android-themes-and-styles/ that is good guide.

like image 60
Konstantin Burov Avatar answered Sep 23 '22 07:09

Konstantin Burov


You can put custom image in radiobutton like normal button. for that create one XML file in drawable folder e.g

<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 radiobutton

and use this file to RadioButton like:

android:button="@drawable/aus" android:layout_height="120dp" android:layout_width="wrap_content"  
like image 30
Chirag Avatar answered Sep 22 '22 07:09

Chirag