一个专为自动按照自定义规则格式化文本输入的 Android 库
Android library designed for automatic formatting of text input by custom rules.
Add to the build.gradle of your app module:
dependencies {
compile 'ru.tinkoff.decoro:decoro:$latestVersion'
}String formattingIn examples below the content of the String text will be formatted according to a mask.
Mask mask = new MaskImpl(PredefinedSlots.RUS_PHONE_NUMBER, true);
mask.insertFront("9995554433");
System.out.println(mask.toString()); // +7 (999) 555-44-33Example 2:
Slot[] slots = new UnderscoreDigitSlotsParser().parseSlots("___ ___");
Mask mask = MaskImpl.createTerminated(slots); // 'terminated' mask
mask.insertFront("9995554433");
System.out.println(mask.toString()); // 999 555Example 3:
Slot[] slots = new UnderscoreDigitSlotsParser().parseSlots("___ ___");
Mask mask = MaskImpl.createNonTeminated(slots); // 'non-terminated' mask
mask.insertFront("9995554433");
System.out.println(mask.toString()); // 999 5554433In examples below all the user's text input to EditText will be formatted according to a mask.
MaskImpl mask = MaskImpl.createTerminated(PredefinedSlots.CARD_NUMBER_USUAL);
FormatWatcher watcher = new MaskFormatWatcher(mask);
watcher.installOn(editText); // install on any TextView
…Slot[] slots = new UnderscoreDigitSlotsParser().parseSlots("___ ___ ___");
FormatWatcher formatWatcher = new MaskFormatWatcher(MaskImpl.createTerminated(slots));
formatWatcher.installOn(editText); // install on any TextView
In version 1.1.0 class FormatWatcherImpl was renamed to DescriptorFormatWatcher.
Also this version introduced MaskFormatWatcher that offers more clean API than DescriptorFormatWatcher.
More examples and details can be found in our wiki (in Russian yet).
暂无开放 Issues,或尚未同步最近议题。