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:pagingnavigation:latest'
}
The PagerNavigationView is very easy to use. Just add it to your layout like any other view.
Here's a basic implementation.
<id.co.edtslib.pagingnavigation.PagingNavigation
android:id="@+id/navigation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:count="6"
app:shape="@drawable/bg_test"
app:shapeSize="@dimen/dimen_8dp"
app:shapeSelectedWidth="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
[integer]: size of pager
[integer]: shape form resource id, default
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- shape for selection -->
<item android:state_selected="true">
<shape android:shape="oval">
<solid android:color="#1171D4" />
</shape>
</item>
<!-- shape for defaul -->
<item>
<shape android:shape="oval">
<solid android:color="#DCDEE3" />
</shape>
</item>
</selector>
[dimension]: size of shape, default 4dp
[dimension]: size of shape if selected, default = shapeSize
[reference]: space between shape, default 8dp
You can set a listener to be notified when the user click the PagingNavigation. An example is shown below.
val navigation = findViewById<PagingNavigation>(R.id.navigation)
navigation.delegate = object : PagingNavigationDelegate {
override fun onSelected(position: Int) {
Toast.makeText(this@MainActivity, "Selected Index $position",
Toast.LENGTH_SHORT).show()
}
}
For convenience, many of the PagingNavigation attributes can be set via code.
// set size of pager
var count: Int = 0
// selected index of shape
var selectedIndex: Int = -1