Android:在哪里可以找到 RadioButton Drawable?

发布于 2024-08-31 10:46:20 字数 474 浏览 1 评论 0原文

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

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

现在一切正常,我扩展了 RelativeLayout 并实现了 Checkable 接口。

但是,我陷入了一个非常简单的问题:在哪里可以找到 CheckedTextViewRadioButton 使用的 Drawable

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

有什么办法可以得到这些 Drawables 或以某种方式解决问题吗?

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 a Spinner.

It's all working fine now, I extended RelativeLayout and implemented Checkable interface.

However, I am stuck on a quite simple problem: Where can I find the Drawable that CheckedTextView and RadioButton use?

I looked at the sourcecode of both, and they seem to use com.android.internal.R. Well... that's internal stuff. So I can't access it.

Any way to get these Drawables or solve the problem somehow?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

Smile简单爱 2024-09-07 10:46:20

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

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

混吃等死 2024-09-07 10:46:20

为了完整起见:

这里有一些代码片段,向您展示我如何让它与上面接受的答案一起工作。

 //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();

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)
 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();
笔芯 2024-09-07 10:46:20

要使用新的默认动画单选按钮可绘制,正确的答案在 @sidon 的注释中:

?android:attr/listChoiceIndicatorSingle

在相对于文本的自定义位置中使用它:

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

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"
    />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文