在Android中制作带有图像的RadioGroup单选按钮...如何? [英] 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
成员,从 CompoundButton
派生.
The RadioButton
class has a buttonDrawable
member, derived from CompoundButton
.
可以通过多种方式更改此可绘制对象.
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
- Add a new selector xml by rightclicking your res folder -> New -> Android xml -> select Drawable in the upper dropdown -> choose selector (in eclipse)
- To setup this selector, please take a look at this link
- From now on you can set your freshly created selector to any of your checkboxes/radiobuttons by using its id.
这篇关于在Android中制作带有图像的RadioGroup单选按钮...如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文