Easy to use and highly customizable OTP Input.
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'
}
<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"/>
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()
XML Attribute | Format | Description |
---|---|---|
android:textStyle | bold | normal | italic | Sets text size for input fields |
android:textSize | dimension | Text size of text in input fields |
android:textColor | color | Sets input field(s) text color |
app:inputBackground | color | Sets the background color for input fields |
app:inputCount | integer | Sets the number of fields to create for otp |
app:inputRadius | dimension | Sets input field radius. For achieving curved corners |
app:inputSpacing | dimension | Space to create in between input fields |
app:inputType | number | numberPassword | Specify Input Type to use. |