Skip to content

hanggrian/pinview

Repository files navigation

CircleCI Codecov Maven Central Android SDK
Figma Layers Pinterest

PinView

Customizable pin input field with a jumping cursor.

  • Inflate custom EditText from XML.
  • Tracks user input and state changes.

Download

repositories {
    google()
    mavenCentral()
}
dependencies {
    compile "com.hanggrian:pinview:$version"
}

Usage

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) -> {
    // ...
});

Use custom 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"/>

About

Customizable pin input field with a jumping cursor

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages