Hello Friends
This is a OTP View dependency for android project. Simply you can add this library in your project and design accroding to your requirements.
In a image shows all OTP views and you can check a example code from source code. Simply you can dawnload a github project or open the Main Activity class and xml file.
Step 1. Add the JitPack repository to your build file. 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.rajputmukesh748:MukeshOtpView:1.0.0'
}
<com.mukesh.mukeshotpview.mukeshOtpView.MukeshOtpView
android:id="@+id/simpleOtpView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:inputType="number"
android:text="124356"
android:textColor="@android:color/black"
android:textSize="18sp"
app:hideLineWhenFilled="false"
app:itemCount="6"
app:lineColor="@android:color/holo_red_light"
app:state_filled="true"
app:viewType="line"
/>
<com.mukesh.mukeshotpview.mukeshOtpView.MukeshOtpView
android:id="@+id/inBuildRectangleOtpView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:inputType="number"
android:text="124356"
android:textColor="@android:color/black"
android:textSize="18sp"
app:hideLineWhenFilled="false"
app:itemCount="6"
app:lineColor="@android:color/holo_red_light"
app:state_filled="true"
app:viewType="rectangle"
/>
<com.mukesh.mukeshotpview.mukeshOtpView.MukeshOtpView
android:id="@+id/customOtpView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:inputType="number"
android:text="124356"
android:itemBackground="@drawable/gray_round_corners"
android:textColor="@android:color/black"
android:textSize="18sp"
app:hideLineWhenFilled="false"
app:itemCount="6"
app:lineColor="@color/colorAccent"
app:state_filled="true"
app:viewType="none"
/>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="mukeshOtpStyle">@style/OtpWidget.OtpView</item>
</style>
<style name="OtpWidget.OtpView" parent="Widget.AppCompat.EditText">
<item name="android:background">@null</item>
<item name="android:minHeight">0dp</item>
<item name="android:maxLines">1</item>
</style>
simpleOtpView.setOtpCompletionListener(object : MukeshOtpCompleteListener {
override fun otpCompleteListener(otp: String?) {
Toast.makeText(
this@MainActivity,
"Entered OTP Number is $otp",
Toast.LENGTH_LONG
).show()
}
})