Making RadioGroup radio buttons with images in Android... How?(在Android中制作带有图像的RadioGroup单选按钮......如何?)
问题描述
是否可以在 Android 中制作单选按钮,其中有按钮的图像表示而不是常规按钮?我希望它看起来像这样:
Is it possible to make Radio Buttons in Android, where there are image representation to a button instead of a regular buttons? I want it to look something like that:
中间的青色代表被选中的按钮.
The cyan in the middle represents the selected button.
我该怎么做?
推荐答案
RadioButton
类有一个 buttonDrawable
成员,派生自 复合按钮
.
您可以通过多种方式更改此可绘制对象.
There are multiple ways you can change this drawable.
来自 java:
myRadioButton.setButtonDrawable(resourceId or Drawable);
来自 xml:
<RadioButton
android:button="@drawable/yourdrawable"
...
/>
如果您只是希望选中/未选中状态看起来不同,那么
If you just want the checked/unchecked state look differently, then
- 通过右键单击您的 res 文件夹 -> 新建 -> 添加新的选择器 xmlAndroid xml -> 在上方下拉列表中选择 Drawable -> 选择选择器(在 Eclipse 中)
- 要设置此选择器,请查看此 链接
- 从现在开始,您可以将新创建的选择器设置为您的任何复选框/单选按钮,使用其 id.
这篇关于在Android中制作带有图像的RadioGroup单选按钮......如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在Android中制作带有图像的RadioGroup单选按钮......如何?


- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01