Skip to content

edtslib/slidingbutton

Repository files navigation

SlidingButton

SlidingButton

Setup

Gradle

Add this to your project level build.gradle:

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

Add this to your app build.gradle:

dependencies {
    implementation 'com.github.edtslib:slidingbutton:1.0.4'
}

Usage

The SlidingButton is very easy to use. Just add it to your layout like any other view.

Via XML

Here's a basic implementation.

    <id.co.edtslib.slidingbutton.SlidingButton
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:id="@+id/slidingButton"
        android:layout_marginStart="16dp"
        android:layout_marginEnd="16dp"
        android:layout_marginTop="16dp"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:text="Hello World!" />

Attributes information

An example is shown below.

        app:activated="true"
        app:textColor="@color/test_color"
        app:slideColor="#ffff00"
        app:arrowColor="@color/bg_arrow"
        app:textStyle="@style/TextStyle"
app:text

[string]: text of button

app:activated

[boolean]: true is mean initial state of SlidingButton is enabled for slide, default true

app:textColor

[integer]: color resource of button text, default:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- normal button text color -->
    <item android:color="#FFFFFF" android:state_activated="false" />
    <!-- slide over button text color -->
    <item android:color="@color/colorBlue" android:state_activated="true" />
</selector>
app:textStyle

[reference]: style of button text, default not set

app:slideColor

[color]: color of slide, default blue

app:arrowColor

[reference]: color resource of arrow container, default:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- color when arrow drag -->
    <item android:color="#ffffff" android:state_selected="true"/>
    <!-- color when arrow idle -->
    <item android:color="@color/colorBlue"/>
</selector>

Listening for slide actions on the SlidingButton

You can set a listener to be notified when the user slides across the SlidingButton. An example is shown below.

        val slidingButton = findViewById<SlidingButton>(R.id.slidingButton)
        slidingButton.delegate = object : SlidingButtonDelegate {
            override fun onCompleted() {
                Toast.makeText(this@MainActivity, "Add some action on here", Toast.LENGTH_SHORT).show()
            }
        }

Method for slide actions on the SlidingButton

    // enabled/disabled slide button view
    override fun setActivated(activated: Boolean)
    
    // reset slide button to initial state 
    fun reset()

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages