是否有可能在Android 微调控件中更改radio button
的颜色。默认情况下,它显示单选按钮的绿色。Android - 自定义微调控件外观
我需要将其更改为其他一些颜色,这是可能的,以及如何?
是否有可能在Android 微调控件中更改radio button
的颜色。默认情况下,它显示单选按钮的绿色。Android - 自定义微调控件外观
我需要将其更改为其他一些颜色,这是可能的,以及如何?
我知道这是一个老问题了,但在这里不用...
您需要创建一个自定义主题,并将其应用到您的微调活动。
首先,您需要为'新'收音机的选中/未选中状态创建图像,您可以从sdk的res/drawable-*
文件夹中提取给定图像btn_radio_on.png
和btn_radio_off.png
。编辑它们以查看你想要的方式(例如更改颜色或其他)并保存到项目中。
接下来,创建一个在您res/values
文件夹一个新的XML文件,并添加以下内容:
<resources>
<style name="CustomSpinnerRadioTheme" parent="@android:style/Theme">
<item name="android:spinnerDropDownItemStyle">@style/EditedRadio</item>
</style>
<style name="EditedRadio" parent="@android:style/Widget.DropDownItem.Spinner">
<item name="android:checkMark">@drawable/edited_radio</item>
</style>
</resources>
然后,创建res/drawable
另一个XML文件命名为edited_radio.xml
,并且它应该包含以下内容:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="false" android:drawable="@drawable/btn_radio_off" />
<item android:state_checked="true" android:drawable="@drawable/btn_radio_on" />
</selector>
只要确保参考您已编辑的图像的检查状态。然后,您只需将CustomSpinnerRadioTheme
应用到您的活动并运行!
一个很好的资源,我发现是Applying Styles and Themes尤其是在Android Styles (styles.xml)和Android Themes (themes.xml)
断开链接的附加参考... – Prakash 2014-11-20 15:44:50