0

How to set

 android:drawableTop="@drawable/your_drawable_selector" 

through java for a RadioButton in android?

sasikumar
  • 12,540
  • 3
  • 28
  • 48
JITHIN GOPAL
  • 131
  • 1
  • 14

1 Answers1

0

You can use setCompoundDrawablesWithIntrinsicBounds, since RadioButton is a subclass of TextView. E.g.

radioButton.setCompoundDrawablesWithIntrinsicBounds (0, R.drawable.your_drawable_selector, 0, 0).

If you have a Bitmap you can use

Drawable drawable =  new BitmapDrawable(getResources(), yourBitmap);
radioButton.setCompoundDrawablesWithIntrinsicBounds(null, drawable, null, null); 

From the documentation

Sets the Drawables (if any) to appear to the left of, above, to the right of, and below the text. Use 0 if you do not want a Drawable there. The Drawables' bounds will be set to their intrinsic bounds.

Blackbelt
  • 156,034
  • 29
  • 297
  • 305