Simple Android SwipeButton
Example: https://github.com/Sub4ikGG/swipebuttonexample
Step 1. Add the JitPack repository to your build file
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
allprojects {
repositories {
...
maven(url = "https://jitpack.io")
}
}
Step 2. Add the dependency
dependencies {
...
// SwipeButton
implementation 'com.github.Sub4ikGG:swipebutton:1.0.0'
}
dependencies {
...
// SwipeButton
implementation("com.github.Sub4ikGG:swipebutton:1.0.0")
}
Add View to your layout
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<...>
<ru.chatan.swipebutton.SwipeButton
android:id="@+id/swipe_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="32dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:swipeDrawable="@drawable/arrow"
app:swipeText="SWIPE ME!"
app:swipeTextColor="@color/black"
app:swipeTextSize="14sp"
app:swipeThumbColor="@color/light_blue"
app:swipeProgressColor="@color/light_blue" />
<...>
</androidx.constraintlayout.widget.ConstraintLayout>
app:swipeDrawable - thumb drawable
app:swipeText - swipeButton text
app:swipeTextColor - color for your text
app:swipeTextSize - textSize for the text
app:swipeThumbColor - thumb color
app:swipeProgressColor - the color that will fill swipeButton
swipeButton.setListener(
object : SwipeButton.OnSwipeButtonListener {
override fun onSwiped() {
// TODO: Do something here
}
}
)
// if you want to return default text use 'setDefaultText = true'
// defaultText is taken from app:swipeText
swipeButton.reload(setDefaultText = true)
swipeButton.setText(text = "Text")
// Changing default text that represented in app:swipeText
swipeButton.setDefaultText(defaultText = "Text")
Copyright 2023 Kirill Efremov
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.