EditTextPin for Android
This is a simple library for android where we can take an OTP input from the user. This library will take only number input for now. The lenght is six digits. This library handles both insering and deleting of numbers. You can get the pin using getPin() function.
- Step 1. Add the JitPack repository to your build file
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
- Step 2. Add the dependency (only for androidx projects)
dependencies {
implementation 'com.github.hexdecimal16:EditTextPin:Version'
}
<com.dhairytripathi.library.EditTextPin
android:id="@+id/editTextPin"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
EditTextPin editTextPin = findViewById(R.id.editTextPin);
String pin = editTextPin.getPin(); //To get the current entered pin
You're able to further customize or set initial values with styled attributes:
- Add res-auto to your xml layout if you haven't yet
xmlns:app="http://schemas.android.com/apk/res-auto"
- After that the following attributes will become available:
app:underlineColor="" <!-- To change underline color-->
app:textBackground="" <!-- Add a drawable to Edit Text background (For api 23+) -->