如何更改切换按钮的颜色? [英] How to change color of the toggle button?

查看:137
本文介绍了如何更改切换按钮的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
  变化与ldquo;关于”的交换机颜色

Possible Duplicate:
Change “on” color of a Switch

我需要有一个切换按钮改变颜色,当它改变状态从绿色(真),以红色(假)。如何我可以改变切换按钮的颜色? 感谢..

I need to have a toggle button change color when it changes state from Green(true) to Red(false).how can i change toggle button color? thanks..

推荐答案

中创建一个名为水库XML colors.xml /值文件夹:

Create a xml named colors.xml in res/values folder:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="red">#ff0000</color>
    <color name="green">#00ff00</color>
</resources>

在绘制文件夹中,创建一个XML文件my_btn_toggle.xml:

In drawable folder, create a xml file my_btn_toggle.xml:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="false" android:drawable="@color/red"  />
    <item android:state_checked="true" android:drawable="@color/green"  />
</selector>

在XML部分定义的切换按钮,地址:

and in xml section defining your toggle button add:

android:background="@drawable/my_btn_toggle

这篇关于如何更改切换按钮的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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