Skip to content

An android view component library for One Time Password / Passcode Input

License

Notifications You must be signed in to change notification settings

virtual-addy/OtpInput

Repository files navigation

Easy to use and highly customizable OTP Input.

Otp Input Android Screenshot

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()

XML Attributes

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.

About

An android view component library for One Time Password / Passcode Input

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages