如何改变在Android的切换按钮的背景颜色 [英] how to change the background color of the toggle button in android

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

问题描述

我试图改变使用XML文件作为白的颜色,但切换按钮切换按钮的背景颜色是完全损坏,它看起来像所有的按钮上铺满了白色。有切换按钮没有迹象显示ON或OFF时,我已经改变了切换按钮的颜色为白色。任何一个可以请告诉我,是否还有其他的方法来改变,不会破坏切换按钮的显示背景。

i tried to change the background color of the toggle button using XML file as white color but the toggle button is totally damaged it look like all the button was covered with white. There is no indication of ON or OFF on the toggle button when i have changed the color of the toggle button to white. Can any one please tell me, Is there is any other way to change the background which will not damage the indication of the toggle button .

<ToggleButton android:id="@+id/togglebutton"
android:layout_width="100px"
android:layout_height="46px"
android:background="#ffffff"
android:layout_above ="@+id/save"
android:textOn="DAY"
android:textOff="NIGHT" />

这是我的XML code认准切换按钮

this is how my XML code look for the toggle button

推荐答案

是有一种方式,你想改变的背景,但你必须使用一个选择这样的背景:

Yes there is a way to change the background as you wish but you have to use a selector like this as background:

<selector
xmlns:android="http://schemas.android.com/apk/res/android"
>
<item
    android:state_focused="true"
    android:state_pressed="false"
    android:drawable="@drawable/some_image" />
<item
    android:state_focused="true"
    android:state_pressed="true"
    android:drawable="@drawable/some_other_image" />
<item
    android:state_focused="false"
    android:state_pressed="false"
    android:drawable="@drawable/some_image1" />
<item
    android:state_focused="false"
    android:state_pressed="true"
    android:drawable="@drawable/other_image" />
</selector>

有关@可绘制的/ etc(可以使用一种颜色或进行梯度检查<一href="http://android-$c$cs-examples.blogspot.com/2011/04/animated-customized-popup-transparent.html">this有关渐变更多信息

For @Drawable/etc (you can use a color or make a gradient. Check this for more info about gradients

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

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