前言

Android中的Switch控件很使用,比如WiFi开关等。Switch可以提供切图,也可以自定义属性。本文就是主要介绍自定义。

记录一下,方便自己查阅和回顾。

正文

activity_main.xml

<Switch
    style="@style/Widget.AppCompat.CompoundButton.Switch"
    android:layout_width="200dp"
    android:layout_height="50dp"
    android:showText="true"
    android:textColor="@color/default_color_0"
    android:textOff="Off"
    android:textOn="On"
    android:textSize="@dimen/text_default_size"
    android:thumb="@drawable/switch_thumb_bg"
    android:track="@drawable/switch_track_bg"
    tools:ignore="UseSwitchCompatOrMaterialXml" />

这里主要是自定义thumb和track的资源。存放目录

drawable/switch_thumb_bg.xml
drawable/switch_thumb_on_bg.xml
drawable/switch_thumb_on_bg.xml
drawable/switch_thumb_off_bg.xml

隐藏内容!
评论后才能查看!

参考文章

  1. Android中的Switch控件

相关文章

暂无评论

none
暂无评论...