android.com switch,How can I style an Android Switch?

本文介绍了如何为Android的Switch组件定义背景和切换部分的可绘制资源,通过设置不同的状态选择器来改变开关的样式。内容包括了拇指、轨道的四种状态图片以及背景的三种状态选择器的详细说明,并提供了实现自定义风格的步骤。
摘要由CSDN通过智能技术生成

You can define the drawables that are used for the background, and the switcher part like this:

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:thumb="@drawable/switch_thumb"

android:track="@drawable/switch_bg" />

Now you need to create a selector that defines the different states for the switcher drawable.

Here the copies from the Android sources:

This defines the thumb drawable, the image that is moved over the background. There are four ninepatch images used for the slider:

The deactivated version (xhdpi version that Android is using)

mUmF8.png

The pressed slider:

a1a9748a34cb0252be875c81fc3481a9.png

The activated slider (on state):

37f9fafb28d84e6c32cb4e8364cc978e.png

The default version (off state):

76dcc4943f00557ebc79541e214abfc4.png

There are also three different states for the background that are defined in the following selector:

The deactivated version:

85743b7bf39624d396173c1d00a60141.png

The focused version:

36b251f6602ad31f0e3322ed42d8b0b0.png

And the default version:

5e69cc22fc04e16d8f55c1b63e6dc568.png

To have a styled switch just create this two selectors, set them to your Switch View and then change the seven images to your desired style.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值