如何自定义开关按钮? [英] How to custom switch button?

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

问题描述

我期待为自定义的开关按钮成为如下:

I am looking to Custom The Switch Button to becoming as following :

如何实现这一目标?

推荐答案

您可以使用下面的code改变的颜色文字

you can use the following code to change color and text :

<org.jraf.android.backport.switchwidget.Switch
                        android:id="@+id/th"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        app:thumb="@drawable/apptheme_switch_inner_holo_light"
                        app:track="@drawable/apptheme_switch_track_holo_light"
                        app:textOn="@string/switch_yes"
                        app:textOff="@string/switch_no"
                        android:textColor="#000000"
                        />

中创建一个名为水库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

要改变的颜色纹元 textOff

android:switchTextAppearance="@style/Switch"

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

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