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单选按钮......如何?
基础教程推荐
- NSString intValue 不能用于检索电话号码 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
