在Android中制作带有图像的RadioGroup单选按钮...如何? [英] Making RadioGroup radio buttons with images in Android... How?

查看:319
本文介绍了在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

  • 通过右键单击res文件夹->新建->添加新的选择器xml. Android xml->在上方下拉菜单中选择Drawable->选择 选择器(在日食中)
  • 要设置此选择器,请查看以下
  • 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆