Customizable pin input field with a jumping cursor.
- Inflate custom
EditText
from XML. - Tracks user input and state changes.
repositories {
google()
mavenCentral()
}
dependencies {
compile "com.hanggrian:pinview:$version"
}
Declare view in xml layout.
<com.hanggrian.pinview.PinGroup
android:id="@+id/pinGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:pinTextAppearance="@style/TextAppearance.AppCompat.Display2"
app:pinCount="6"/>
Then in Java.
PinGroup view = findViewById<>(R.id.pinView);
CharSequence pin = view.getText();
view.setOnStateChangedListener((view, isComplete) -> {
// ...
});
view.setOnPinChangedListener((view, pin) -> {
// ...
});
Make a class that extends PinView
.
package com.example;
public class CustomPinView extends PinView {
public CustomPinView(Context context) {
super(context);
doSomething();
}
}
Then refer to that class in xml, there is no way to do change it programmatically.
<com.hanggrian.pinview.PinGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:pinView="com.example.CustomPinView"/>