美文网首页
仿照ios开关选择的自定义控件

仿照ios开关选择的自定义控件

作者: 爱投篮的安德森 | 来源:发表于2017-08-03 13:42 被阅读17次

带有阴影选择,开关背景颜色的选择效果 [github]: https://github.com/yanjiabin/SwitchView

step1 在project目录的build.gradle的allprojects节点添加

 maven { url "https://jitpack.io" }

step2 在自己Modul的build.gradle中添加

dependencies {
         compile 'com.github.yanjiabin:SwitchView:-SNAPSHOT'
    }

开始使用

  • 在你的布局文件
<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:background="#fff"
        android:paddingLeft="15dp"
        android:paddingRight="15dp">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerInParent="true"
            android:gravity="center"
            android:text="名称"
            android:textColor="#000"
            android:textSize="16sp" />

        <com.github.yanjiabin.switchview.SwitchView
            android:id="@+id/name"
            android:layout_width="60dp"
            android:layout_height="30dp"
            android:layout_alignParentRight="true"
            android:layout_centerInParent="true" />
    </RelativeLayout>
    ... 
  • SwitchView的API:

  <declare-styleable name="SwitchView">
        <attr name="hasShadow" format="boolean" />   这个属性是表示是否要阴影效果
        <attr name="primaryColor" format="color" />  这个属性是表示背景的颜色
        <attr name="primaryColorDark" format="color" />
        <attr name="isOpened" format="boolean" />    默认是开还是关true表示的开false表示的关
    </declare-styleable>

相关文章

网友评论

      本文标题:仿照ios开关选择的自定义控件

      本文链接:https://www.haomeiwen.com/subject/odkplxtx.html