1

I have a radio button which I want to change the little selected icon based on a state, however its a simple on, off state. Basically I want to make it look like an LED, I have a red image and a green image and when it is checked I want it to be green and when it is not checked I want it to be red.

Green red

Currently the options I have tried, just stick the image in the background of the whole view, and not just the small circle area. like so

enter image description here

I have my two drawables generated from http://android-holo-colors.com/

radio_red.png and radio_green.png

1
  • are you using the background property? Commented Apr 30, 2014 at 8:26

2 Answers 2

4

You have to set your radiobutton's background from Java code:

radioButton.setButtonDrawable(R.drawable.custom_radiogroup_divider);

It works with checkbox too ;)

Sign up to request clarification or add additional context in comments.

Comments

2

Create a state list drawable (see this page) and use the android:button attribute on your RadioButton. If you want to really make sure you cover all the states, you can find the source used for Android's default radio button indicator and just swap out the drawable names. You can find that file somewhere in your [android-sdk-directory]/platforms/android-#/data/res/drawable folder.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.