Android的 - 自定义微调部件外观及感觉 [英] Android - Customizing the Spinner widget Look and Feel

查看:129
本文介绍了Android的 - 自定义微调部件外观及感觉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能改变的单选按钮在Android 微调部件的颜色。默认情况下它会显示绿色的单选按钮。

Is it possible to change the color of the radio button in the Android spinner widget. By default it displays the green color for the radio button.

我需要将其更改为其他的颜色,它是可能的,如何?

I need to change it to some other color, is it possible, and how?

推荐答案

我知道这是一个老问题了,但在这里不用...

I know this is an old question now, but here goes...

您需要创建一个自定义主题,并将其应用到您的微调活动。

You will need to create a custom Theme and apply it to the Activity with your spinner.

首先,您需要创建图像的新电台的选中/取消选中状态,你可以只拉定的图像 btn_radio_on.png 和<$ C从SDK的水库$ C> btn_radio_off.png /绘制 - * 文件夹(S)。编辑看你怎么想(如改变颜色或其他),并关闭保存到您的项目。

First, you need to create images for the checked/unchecked states of the 'new' radio, you could just pull the given images btn_radio_on.png and btn_radio_off.png from the sdk's res/drawable-* folder(s). Edit them to look how you want (such as changing color or whatever) and save off to your project.

接下来,在你的 RES /值一个新的XML文件文件夹,并添加以下内容:

Next, create a new xml file in your res/values folder, and add the following:

<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>

然后,创建水库另外一个XML文件/绘制 edited_radio.xml ,它应该包含以下

Then, create another xml file in res/drawable named edited_radio.xml, and it should contain the following:

<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 您的活动和运行!

有一个很好的资源,我发现是应用样式和主题的特别附加参考的<一个href="http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/res/res/values/styles.xml">Android样式(styles.xml)和<一href="http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/res/res/values/themes.xml">Android主题(的themes.xml)

A good resource I found is Applying Styles and Themes especially the additional reference on Android Styles (styles.xml) and Android Themes (themes.xml)

这篇关于Android的 - 自定义微调部件外观及感觉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆