Skip to content

Latest commit

 

History

History
94 lines (66 loc) · 1.82 KB

README.md

File metadata and controls

94 lines (66 loc) · 1.82 KB

English | 简体中文

FormatEdit

An easy to use format edit library for Android.

Maven Central API License

Download

repositories {
    mavenCentral()
}

dependencies {
    implementation 'cc.taylorzhang:format-edit:1.1.0'
}

Usage

Format edit phone

layout:

<androidx.appcompat.widget.AppCompatEditText
    android:id="@+id/etPhone"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="number" />

kotlin:

// format is ' '
etPhone.setFormatRules(3, 4, 4)

// format is '-'
etPhone.setFormatRules(3, 4, 4, formatChar = '-')

Format edit ID number

layout:

<androidx.appcompat.widget.AppCompatEditText
    android:id="@+id/etIDNumber"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:digits="@string/digits_id_number"/>

resources:

<string name="digits_id_number">0123456789xX</string>

kotlin:

etIDNumber.setFormatRules(6, 4, 4, 4)

Set listener

etPhone.setOnFormatEditListener { isComplete, text ->
    if (isComplete) { // edit complete
        // toast current text with format removed.
        Toast.makeText(this, text, Toast.LENGTH_SHORT).show()
    }
}

Text with format removed

etPhone.textWithFormatRemoved

License

Apache license 2.0 © Taylor Zhang