Skip to content Skip to sidebar Skip to footer

Android: Where To Find The Radiobutton Drawable?

Ok, I am trying to create a custom view called CheckedRelativeLayout. It's purpose is the same as a CheckedTextView, to be able to use it in a list of items you want selected or in

Solution 1:

look under SDK folder /platforms/android-2.0/data/res/ you can access them by either android.R.drawable ( if public ) or need to copy them as drawable to your project

Solution 2:

For sake of completeness:

Here some code pieces that show how you I got it working with above accepted answer.

//Image Setup (Once when creating this view)ImageViewindicator= (ImageView) findViewById(R.id.RadioStatusImage);
 indicator.setImageDrawable(getResources().getDrawable(android.R.drawable.btn_radio));

 //State Change (In some other method)
  android.R.attr.state_checked
  if(isChecked)
  {
     indicator.setImageState(android.R.attr.state_checked, false);
  }
  else
  {
     indicator.setImageState(View.ENABLED_STATE_SET, false);
  }
  invalidate();

Solution 3:

To use the new default animated radio button drawable, the correct answer is in the comment of @sidon:

?android:attr/listChoiceIndicatorSingle

Using this in the custom position relative to text:

<RadioButton...android:gravity="center_horizontal|bottom"android:drawableTop="?android:attr/listChoiceIndicatorSingle"android:button="@null"
    />

Post a Comment for "Android: Where To Find The Radiobutton Drawable?"