android LSwitch控件

效果图

android LSwitch控件         android LSwitch控件

 

build.gradle(Module: app)

dependencies {
    ......
    //开关控件LSwitch
    implementation 'com.github.liys666666:LSwitch:V1.0.4'

}

build.gradle(Project: 项目名)

allprojects {
    repositories {
          ......
        //maven包
        maven { url 'https://jitpack.io' }
    }
}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="主界面"
    android:textSize="40sp">

</TextView>
<com.liys.lswitch.LSwitch
    android:id="@+id/l_switch"
    android:layout_width="55dp"
    android:layout_height="35dp"
    app:track_radius="25dp"
    app:track_height="30dp"
    app:thumb_radius="25dp"
    app:thumb_height="30dp"
    app:thumb_width="30dp"
    app:checked="false"
    app:animator_duration="100"
    app:track_color_off="#627EFE"
    app:thumb_color_off="#FFFFFF" />

</LinearLayout>
MainActivity
public class MainActivity extends BaseActivity {
    private LSwitch lSwitch;


    @Override
    protected int getView() {
        return R.layout.activity_main;
    }

    @Override
    protected void initView() {
        lSwitch = findViewById(R.id.l_switch);
        lSwitch.setOnCheckedListener(new BaseSwitch.OnCheckedListener() {
            @Override
            public void onChecked(boolean isChecked) {
                //选中后执行
            }
        });
    }

    @Override
    protected void method() {

    }
}

 

上一篇:public/private/protected的具体区别


下一篇:C++ 类的继承方式