Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.bbqbaron:swipe-button:0.8.5'
}
dependencies {
implementation("com.github.bbqbaron:swipe-button:0.8.5")
}
<dependency>
<groupId>com.github.bbqbaron</groupId>
<artifactId>swipe-button</artifactId>
<version>0.8.5</version>
</dependency>
libraryDependencies += "com.github.bbqbaron" % "swipe-button" % "0.8.5"
:dependencies [[com.github.bbqbaron/swipe-button "0.8.5"]]
Library of an android button activated by swipe.
compile 'com.ebanx:swipe-button:[latestVersion]'
Add the button in your layout file and customize it the way you like it.
<com.ebanx.swipebtn.SwipeButton
android:id="@+id/swipe_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
app:inner_text="SWIPE"
app:inner_text_color="@android:color/white"
app:inner_text_size="16sp"
app:inner_text_top_padding="18dp"
app:inner_text_bottom_padding="18dp"
app:inner_text_background="@drawable/shape_rounded"
app:button_image_height="60dp"
app:button_image_width="100dp"
app:button_image_disabled="@drawable/ic_lock_open_black_24dp"
app:button_image_enabled="@drawable/ic_lock_outline_black_24dp"
app:button_left_padding="20dp"
app:button_right_padding="20dp"
app:button_top_padding="20dp"
app:button_bottom_padding="20dp"
app:button_background="@drawable/shape_button"
app:initial_state="disabled"
app:has_activate_state="true"
/>
You can set the size of the moving part of the button by changing the app:button_image_width and app:button_image_height properties.
You can set the size of the fixed part of the button by setting the text size of the setting the padding in this part.
You can set a listener for state changes
SwipeButton enableButton = (SwipeButton) findViewById(R.id.swipe_btn);
enableButton.setOnStateChangeListener(new OnStateChangeListener() {
@Override
public void onStateChange(boolean active) {
Toast.makeText(MainActivity.this, "State: " + active, Toast.LENGTH_SHORT).show();
}
});
Or listen for the activation of the button
swipeButtonNoState.setOnActiveListener(new OnActiveListener() {
@Override
public void onActive() {
Toast.makeText(MainActivity.this, "Active!", Toast.LENGTH_SHORT).show();
}
});
If you would like to see a front-end version of this button you can check a codepen in this link:
For bugs, feature requests, and discussion please use GitHub Issues.
Written with StackEdit.