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

带有阴影选择,开关背景颜色的选择效果 [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>

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,969评论 19 139
  • afinalAfinal是一个android的ioc,orm框架 https://github.com/yangf...
    passiontim阅读 15,568评论 2 45
  • 苦: 虽说春雨贵如油, 冷雨夜半浅润丘, 农夫望田空欢喜, 粮不值钱种卖愁。
    云之憾阅读 123评论 0 0
  • 早上一见到大哥,大哥又讲到了这句话:自己家人分那么清楚干什么!大哥还问了一句:你说不是?听了大哥的话,我就意识到自...
    香盈秀2013阅读 479评论 0 0
  • ——《娛樂至死》書評 自古以來,人類一直在同一個天然的障礙抗爭:思想被禁錮在一個個軀殼之內。這就意味著,人類的交流...
    Pope怯懦懦地阅读 121评论 0 0