Change radiobat color when pressed

I have one having 3 . By default, when I click on the radio button, it turns Blue . I need to change the color, say when I click the first it should go to Yellow , the second to Blue and the third to Green . RadioGroup

Radio Buttons

I've seen a few tutorials for customizing when customizing radio buttons, such as Can I change the radio button icon in the 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>

      

+3


source to share


1 answer


You can use stylists as 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 will be your blueprints for each button state, you can have multiple selectors for each radio button

0


source







All Articles