是否可以更改 Android 单选按钮组中的单选按钮图标
我想让我的 Android 应用程序的用户能够设置一些参数。单选按钮非常适合这种情况。但是,我不喜欢单选按钮的渲染。
是否可以更改单选按钮图标?例如,是否可以为每一行创建自定义布局,并在该布局中引用我自己的图标并更改字体等。
I am wanting to allow the user of my android application the ability to set some parameters. The radio button is ideal for this situation. However, I don't like the radio buttons are rendered.
Is it possible to change the radio button icon? For example, is it possible to create a custom layout for each row and in that layout reference my own icon and change the font et al.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
是的,您可能必须在 res/values/styles.xml 中为单选按钮定义自己的样式:
这里的“radio”应该是有状态的可绘制,radio.xml:
然后只需将自定义主题应用于整个应用程序或活动由您选择。
有关主题和样式的更多信息,请参阅 http:// /brainflush.wordpress.com/2009/03/15/understanding-android-themes-and-styles/ 这是很好的指南。
Yes that's possible you have to define your own style for radio buttons, at res/values/styles.xml:
'radio' here should be a stateful drawable, radio.xml:
Then just apply the Custom theme either to whole app or to activities of your choice.
For more info about themes and styles look at http://brainflush.wordpress.com/2009/03/15/understanding-android-themes-and-styles/ that is good guide.
您可以像普通按钮一样将自定义图像放入单选按钮中。
为此,在可绘制文件夹中创建一个 XML 文件
例如
,在这里您可以为单选按钮使用 3 个不同的图像
,并将此文件用于单选按钮,如下所示:
You can put custom image in radiobutton like normal button.
for that create one XML file in drawable folder
e.g
Here you can use 3 different images for radiobutton
and use this file to RadioButton like:
仅更改单选按钮的更简单方法是简单地将选择器设置为可绘制右侧
,选择器是:
仅此而已
The easier way to only change the radio button is simply set selector for drawable right
And the selector is:
That's all
是的....`
来自 Xml
和 Java
`
yes....`
from Xml
and from Java
`
这可能是一种快速方法,
通过上面显示的两个图标,您将拥有一个像这样的
RadioGroup< /code> 每个
RadioButton
属性的方向为水平方向Button
提供图标在
CompoundButton
下,Here's probably a quick approach,
With two icons shown above, you shall have a
RadioGroup
something like thisRadioGroup
's orientation to horizontalRadioButton
's Properties, try giving the icon forButton
under
CompoundButton
,如果您想以编程方式执行此操作,
In case you want to do it programmatically,