Android Material Design之SwitchMaterial(四)

  • 老规矩先上图
    在这里插入图片描述

  • 引入

implementation 'com.google.android.material:material:1.4.0'
  • 说明
    该控件就是Switch控件的增强版本,属性基本一致

  • 属性

    属性描述
    android:text文本
    android:textOn滑块打开时显示的文本
    android:textOff滑块关闭时显示的文本
    android:thumb滑块图片
    app:track轨迹图片
    app:switchMinWidth滑块开关的最小长度
    app:switchPadding滑块开关与文本的间距
    android:checked是否选中
    app:splitTrack是否将滑块与轨迹分开
    app:showText是否显示textOn/textOff 文本
    app:thumbTint设置滑块颜色
    app:trackTint设置轨迹颜色
    app:thumbTintMode用于应用滑动按钮色调的混合模式
  • 注意
    设置textOn/textOff 时一定要设置showText=“true”,否则没有效果

  • 源代码

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <com.google.android.material.switchmaterial.SwitchMaterial
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="开关"
        android:textOff=""
        android:textOn=""
        android:checked="true"
        app:showText="true"
        app:splitTrack="true"
        app:switchPadding="5dp"
        app:thumbTint="@color/black"
        app:trackTint="@color/design_default_color_error"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值