3

I have a RadioGroup having 3 Radio Buttons. By default , when I click the radio button, it turns Blue. I need to change the color, say , when I click the first one, it should turn to Yellow, the 2nd one Blue and the 3rd one to Green.

I have seen some tutorials to customize by styling the radio buttons, like Is it possible to change the radio button icon in an android radio button group but it hides all the buttons.

enter image description here

Here is my XML .

<RadioGroup
    android:id="@+id/radioGroup1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/studentImage"
    android:layout_alignParentRight="true"
    android:layout_alignRight="@+id/studentImage"
    android:layout_alignTop="@+id/studentImage"
    android:orientation="horizontal" >

    <RadioButton
        android:id="@+id/rb1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="visible" />

    <RadioButton
        android:id="@+id/rb2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="visible" />

    <RadioButton
        android:id="@+id/rb3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="visible" />
</RadioGroup>
Community
  • 1
  • 1
Aleena
  • 273
  • 4
  • 12
  • You can try [this](http://heliodorj.blogspot.in/2009/04/androids-statelistdrawable-example.html) with different selectors for all radio-buttons. – MysticMagicϡ Aug 07 '14 at 08:11
  • check this link http://stackoverflow.com/questions/16213186/how-to-change-border-color-of-radio-button-in-android – Developer Aug 07 '14 at 08:13
  • 1
    @PerlDeveloper, Thnx for the link, it worked for me. – Aleena Aug 07 '14 at 08:43
  • @Aleena I'm after the same information. Could you please advise on how to achieve this? PearlDeveloper seems to have deleted the comment you found useful... – AndroidDevBro Apr 02 '18 at 17:45

1 Answers1

0

You can use a statelist drawable like I wrote below:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="@drawable/color_pressed" /> <!-- pressed -->
<item android:drawable="@drawable/default_button" /> <!-- default -->
</selector> 

color_pressed and deafult_button would be your drawables for each button's state, you could have multiple selectors for each radio button

Evan
  • 287
  • 4
  • 14
  • When i apply the this style to my radio button like **`android:button="@drawable/radio"`** , it hides the buttons. – Aleena Aug 07 '14 at 08:37