Is it possible to change the radio button icon in an android radio button group(是否可以更改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.
推荐答案
是的,您可能必须在 res/values/styles.xml 中为单选按钮定义自己的样式:
Yes that's possible you have to define your own style for radio buttons, at res/values/styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomTheme" parent="android:Theme">
<item name="android:radioButtonStyle">@style/RadioButton</item>
</style>
<style name="RadioButton" parent="@android:style/Widget.CompoundButton.RadioButton">
<item name="android:button">@drawable/radio</item>
</style>
</resources>
这里的'radio'应该是一个有状态的drawable,radio.xml:
'radio' here should be a stateful drawable, radio.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:state_window_focused="false"
android:drawable="@drawable/radio_hover" />
<item android:state_checked="false" android:state_window_focused="false"
android:drawable="@drawable/radio_normal" />
<item android:state_checked="true" android:state_pressed="true"
android:drawable="@drawable/radio_active" />
<item android:state_checked="false" android:state_pressed="true"
android:drawable="@drawable/radio_active" />
<item android:state_checked="true" android:state_focused="true"
android:drawable="@drawable/radio_hover" />
<item android:state_checked="false" android:state_focused="true"
android:drawable="@drawable/radio_normal_off" />
<item android:state_checked="false" android:drawable="@drawable/radio_normal" />
<item android:state_checked="true" android:drawable="@drawable/radio_hover" />
</selector>
然后只需将自定义主题应用于整个应用或您选择的活动.
Then just apply the Custom theme either to whole app or to activities of your choice.
有关主题和样式的更多信息,请查看 http://brainflush.wordpress.com/2009/03/15/understanding-android-themes-and-styles/ 这是很好的指南.
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.
这篇关于是否可以更改android单选按钮组中的单选按钮图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:是否可以更改android单选按钮组中的单选按钮图标


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