0000Alina
0000Alina
1月前 · 0 人阅读

SlideToggleView

🍎A simple SlideToggleView for Android.

Installation

Gradle

Step 1. Add it in your root build.gradle at the end of repositories:

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

Step 2. Add the dependency

dependencies {
    iimplementation 'com.github.onlyloveyd:SlideToggleView:1.0'
}

Basic Usage

Step 1. Add SlideToggleView into your layout

      <cn.onlyloveyd.slidetoggleview.SlideToggleView
            android:id="@+id/slideToggleView"android:layout_width="match_parent"android:layout_height="56dp"android:layout_marginTop="40dp"android:background="@drawable/slide_bg"app:stv_blockBottomMargin="2dp"app:stv_blockLeftMargin="2dp"app:stv_blockRightMargin="2dp"app:stv_blockTopMargin="3dp"app:stv_remain="80dp"app:stv_slideBlock="@drawable/slide_block"app:stv_text="Slide To Unlock" />

Step 2.(optional)add SlideToggleListener for SlideToggleView

     mBinding.slideToggleView.setSlideToggleListener(newSlideToggleView.SlideToggleListener() {
            @OverridepublicvoidonBlockPositionChanged(SlideToggleViewview, intleft, inttotal,
                    intslide) {
                String content =String.format(Locale.CHINESE, "left: %d - total: %d - slide: %d",
                        left, total, slide);
                mBinding.shimmerTextView.setText(content);
            }

            @OverridepublicvoidonSlideOpen(SlideToggleViewview) {
                Toast.makeText(MainActivity.this, "Slide Toggle is Open",
                        Toast.LENGTH_SHORT).show();
            }
        });

Attributes

AttributeUsage
stv_text居中文字内容
stv_textSize居中文字大小
stv_textColor居中文字颜色
stv_slideBlock滑块图片
stv_blockLeftMargin滑块左间距
stv_blockRightMargin滑块左间距
stv_blockTopMargin滑块顶部间距
stv_blockBottomMargin滑块底部间距
stv_remain滑块打开误差范围值

Basic Result

收藏 0
评论 ( 0 )