A customised EditText view serving the purpose of taking numeric One Time Password from a user. With stunning animation, and high customizability.
- Add custom character limit.
- Use your own color scheme.
- Do not allow user changing cursor position for smooth functioning.
Step 1: Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
maven { url "https://jitpack.io" }
}
}
Step 2. Add the dependency
dependencies {
implementation 'com.github.swapnil1104:OtpEditText:0.0.1'
}
Step 3. Add OtpEditText to your layout file
<com.broooapps.otpedittext2.OtpEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="false"
android:cursorVisible="false"
android:digits="0123456789"
android:inputType="number"
android:maxLength="6"
android:padding="8dp"
android:textSize="30sp"
app:oev_primary_color="@color/red"
app:oev_secondary_color="@color/light_gray"
/>
To set custom length of the OtpEditText, use
android:maxLength="{your length}"
This will automatically generate the right amount of boxes for user to input the code in.
The primary color signifies the boundary of the box that requires input from user. To change that use,
app:oev_primary_color="@color/{your_color}"
The secondary color signifies the boundary of the boxes that do not require input from user. To change that use,
app:oev_secondary_color="@color/{your_color}"
- Specify
android:textSize
according to your needs. - Specify
android:padding
according to your needs, there are no paddings drawn by default. - Specify
android:layout_height
according to thetextSize
you've provided. The view will try to center the text with a vertical biasing of0.6f
.