English | 简体中文
An easy to use format edit library for Android.
repositories {
mavenCentral()
}
dependencies {
implementation 'cc.taylorzhang:format-edit:1.1.0'
}
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 = '-')
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)
etPhone.setOnFormatEditListener { isComplete, text ->
if (isComplete) { // edit complete
// toast current text with format removed.
Toast.makeText(this, text, Toast.LENGTH_SHORT).show()
}
}
etPhone.textWithFormatRemoved
Apache license 2.0 © Taylor Zhang