Skip to content

Latest commit

 

History

History
62 lines (51 loc) · 1.73 KB

File metadata and controls

62 lines (51 loc) · 1.73 KB

SwitchView

Download

DemoApp.apk

Usage

  1. add library

implementation 'com.github.iielse:switchbutton:1.0.5'

  1. xml
<com.github.iielse.switchbutton.SwitchView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>
  1. activity

switchView.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        boolean isOpened = switchView.isOpened();
    }
});

or

switchView.setOnStateChangedListener(new SwitchView.OnStateChangedListener() {
    @Override
    public void toggleToOn(SwitchView view) {
        view.toggleSwitch(true); // or false
    }

    @Override
    public void toggleToOff(SwitchView view) {
        view.toggleSwitch(false); // or true
    }
});

Attributes

attr description
hasShadow 是否显示按钮阴影
primaryColor 开启状态背景色
primaryColorDark 开启状态按钮描边色
offColor 关闭状态描边色
offColorDark 关闭状态按钮描边色
shadowColor 按钮阴影色
ratioAspect 按钮宽高形状比率(0,1] 不推荐大幅度调整
isOpened 初始化默认状态