Android:哪里可以找到RadioButton Drawable?

Pet*_*rdk 7 android radio-button drawable

好的,我正在尝试创建一个名为的自定义视图CheckedRelativeLayout.

它的目的与a相同CheckedTextView,能够在您想要选择的项目列表中使用它Spinner.

现在一切正常,我扩展RelativeLayout并实现了Checkable界面.

不过,我被困在一个很简单的问题:我在哪里可以找到Drawable那个CheckedTextViewRadioButton使用?

我查看了两者的源代码,他们似乎都在使用com.android.internal.R.嗯......那是内部的东西.所以我无法访问它.

任何方式获得这些Drawables或以某种方式解决问题?

Ale*_*voy 13

看看SDK文件夹/platforms/android-2.0/data/res/你可以通过android.R.drawable(如果是公共的)访问它们,或者需要将它们作为drawable复制到你的项目中

  • 要将"btn_radio"用于当前主题,您可以使用"?android:attr/listChoiceIndicatorSingle"作为您的drawable. (5认同)

Pet*_*rdk 5

为了完整起见:

这里有一些代码片段展示了我如何使用上面接受的答案.

 //Image Setup (Once when creating this view)
 ImageView indicator = (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();
Run Code Online (Sandbox Code Playgroud)