SwitchMaterial

remix_alone / 2023-08-31 / 原文

SwitchMaterial:开关选择器

布局:
     <com.google.android.material.switchmaterial.SwitchMaterial
                        android:id="@+id/switch_time"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentRight="true"
                        android:layout_marginRight="10dp"/>

<!--
   属性:
    check:是否开启
    text:文本
    
app:switchPadding:文本和开关之间距离
    android:theme:设置开启时按钮颜色,关闭时按钮颜色,关闭时轨迹颜色
  
    <style name="switch_style" parent="Theme.AppCompat.Light">
<!-- 开启时颜色 -->
<item name="colorControlActivated">#00e6db</item>
<!-- 关闭时颜色-->
<item name="colorControlNormal">#383434</item>
<!-- 关闭时轨迹颜色,因为开启轨迹颜色最好和按钮一致-->
<item name="android:colorForeground">#ecd502</item>
</style>
-->