https://github.com/kyleduo/SwitchButton
这是git地址,类似这种自定义控件的第三方,我们最好不要直接依赖应用,因为一方面jar包导多了会出现一些没必要的问题,也会增加项目大小,我们可以下载下来直接复制到项目中。
把所缺少的资源全部复制好之后,我们直接运用这个控件,设置好他的属性
<social.milin.tech.switchbutton.SwitchButton android:layout_width="100dp" android:layout_height="50dp" style="@style/SwitchButtonStyle" app:kswAnimationDuration="300" app:kswBackDrawable="@drawable/ios_back_drawable" app:kswThumbDrawable="@drawable/ios_thumb_selector" app:kswThumbMarginBottom="-8dp" app:kswThumbMarginLeft="-5dp" app:kswThumbMarginRight="-5dp" app:kswThumbMarginTop="-2.5dp" />
这样就大功告成了~