-7

I want change radio button color depending on it's id.

How can I do that?

mtb
  • 1,350
  • 16
  • 32

1 Answers1

0

Set to the radio buttons the same attribute (in the UI layout)

android:onClick="onRadioButtonClicked"

and in the code you can change the colors.

public void onRadioButtonClicked(View view) {

// Is the button now checked?
boolean checked = ((RadioButton) view).isChecked();

// Check which radio button was clicked
switch(view.getId()) {
    case R.id.radio_1:
        if (checked)
            // change color
        break;
    case R.id.radio_2:
        if (checked)
            // change color
        break;
}

}

Have a look:

Community
  • 1
  • 1
mtb
  • 1,350
  • 16
  • 32