OtpInput
An android view component library for One Time Password / Passcode Input
Install / Use
/learn @virtual-addy/OtpInputREADME
Easy to use and highly customizable OTP Input.
<img src="https://i.ibb.co/mv9313B/Screenshot-1600877653.png" alt="Otp Input Android Screenshot" border="0" height="500">Installation
Step 1. Add the JitPack repository to your build file
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
implementation 'com.github.dev-niiaddy:OtpInput:1.0.5'
}
Usage
In Xml
<com.godwinaddy.otpinput.OtpInput
android:id="@+id/otpInput"
android:layout_width="0dp"
android:layout_height="80dp"
android:textStyle="normal"
android:textSize="14sp"
app:inputType="number"
android:textColor="@android:color/white"
app:inputBackground="@color/colorPrimary"
app:inputCount="4"
app:inputRadius="10dp"
app:inputSpacing="10dp"/>
Kotlin Code
val otpInput = findViewById<OtpInput>(R.id.otpInput)
// listener for all input fields completed
otpInput.onInputFinishedListener { otpText ->
Log.d("Input Finished", otpText)
}
// listener for otpInput Text Changed with completed status
otpInput.inputChangedListener { inputComplete, otpText ->
Log.d("Input Finished", otpText)
}
// function to focus the OtnInput and show keyboard
otpInput.focusOtpInput()
//get entered otp text input
otpInput.otpText
//reset or clear input
otpInput.reset()
