代码之家  ›  专栏  ›  技术社区  ›  Vinayak Bevinakatti

Android-定制Spinner小部件的外观和感觉

  •  8
  • Vinayak Bevinakatti  · 技术社区  · 16 年前

    有没有可能改变颜色 radio button 在Android中 微调器小部件 . 默认情况下,它显示单选按钮的绿色。

    我要把它改成 颜色,可能吗,怎么可能?

    1 回复  |  直到 14 年前
        1
  •  12
  •   Kevin Dion    15 年前

    我知道这是一个老问题了,但现在。。。

    首先,您需要为“new”收音机的选中/未选中状态创建图像,您只需拉取给定的图像即可 btn_radio_on.png btn_radio_off.png 从sdk的 res/drawable-*

    接下来,在数据库中创建一个新的xml文件 res/values

    <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 命名 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)