MaskedEditText
Extension of EditText that enables masking user input.
Install / Use
/learn @dimitar-zabaznoski/MaskedEditTextREADME
MaskedEditText
Extension of EditText that enables masking user input. <br>Define a mask as shown in the example below and the non user input characters will be added automatically.
Example
User input: 123456789
Mask: +(###) ###-###
Mask character: #
_________________________________
Output: +(123) 456-789
Usage
Include MaskedEditText in your layout XML.
<mk.webfactory.dz.maskededittext.MaskedEditText
android:id="@+id/edit_masked_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/sample_mask"
android:inputType="text"
android:minWidth="200dp"
app:maskededittext_enforceMaskLength="false"
app:maskededittext_mask="###-###-###"
app:maskededittext_maskCharacter="#"
/>
You can also set the mask programatically.
<br>If enforceMaskLength is set to true the length of the text does not exceed the length of the mask.
<br>You can extract the raw user input (without the mask) by calling MaskedEditText.getRawInput(): String
See Sample for more details
Download
** For projects that do not use AndroidX use version 1.0
Gradle
implementation 'mk.webfactory.dz:maskededittext:2.0'
Maven
<dependency>
<groupId>mk.webfactory.dz</groupId>
<artifactId>maskededittext</artifactId>
<version>2.0</version>
<type>pom</type>
</dependency>
Limitations
-
Length input filters <br>The masking of user input, although correct, doesn't play well with
InputFilter.LengthFilter(maxLength)or in XMLandroid:maxLength="10". As a recommendation, usemaskededittext_enforceMaskLengthonly. -
Some Input types <br>Some input types such as
textPasswordortextCapCharacters/Sentences/Wordswill be ignored by the MaskedEditText. Others, like numbers, work well though. -
Additional TextWatchers <br>This component heavily relies on a
TextWatcherto keep the input masked at all times. Adding your own should not cause any problems, but it does - under circumstances, the last change/callback is not reported leaving you poorly updated with the second to last change. <br>Test this carefully if you want to be updated on the user input real time. SeeR.id.txt_raw_inputin MainActivity of the Sample project for a not so great workaround.
Acceptance criteria
- Mask is set in real time as input changes
- Backspace removes masked characters only (raw user input)
- Adding/removing text works anywhere in the current input
- Enforce mask length trims excess text outside of mask. <br> 4.1. ~~Plays well with InputFilter.LengthFilter~~
- ~~Input type is not respected only for non masked characters~~
- Effectively separates raw input from masked input
- Survives configuration changes automatically
- Works on all android versions and devices
Related Skills
node-connect
347.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
108.0kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
347.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
347.2kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
