MaskedEditText
It allows you to add a mask to EditText
Version
2.0.3
Installation
To use this library in your android project, just simply add the following dependency into your build.gradle
dependencies {
compile 'com.vicmikhailau:MaskedEditText:2.0.3'
}
Usage
Just add in xml custom MaskedEditText with attribute app:mask="your_mask" like below:
<com.vicmikhailau.maskededittext.MaskedEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:mask="your_mask" />
Or add TextChangedListener for your EditText like in following code:
MaskedFormatter formatter = new MaskedFormatter("your_mask");
mEditText.addTextChangedListener(new MaskedWatcher(formatter, mEditText));
Object of MaskedWatcher class has got a weakreference to formatter object, so you must to conside this.
For create your mask you need to use following keys:
ANYTHING KEY = *; DIGIT KEY = #; UPPERCASE KEY = U; LOWERCASE KEY = L; ALPHA NUMERIC KEY = A; CHARACTER KEY = ?; HEX KEY = H;
For example: you would like create a mask for a mobile number in format (029)777-77-77. Just use the simple mask "(###)###-##-##".
If you want to get text without mask just use following code:
-
For getting unmasked text for MaskedEditText mEdtMaskedCustom just use
String unamskedString = mEdtMaskedCustom.getUnMaskedString();
-
For getting unmasked text for default EditText just use
String text = mEditText.getText().toString(); String unmaskedString = formatter.formatString(text).getUnMaskedString();
Change Logs
v2.0.3
Bug with getting ?redit ?ard mask was fixed (issue #13).
v2.0.2
Bug with getting unmasked string was fixed (issue #11).
v2.0.1
Bug with mask was fixed.
v2.0.0
Main logic was updated. Bugs with deleting and changing characters inside masked EditText was fixed
v1.1.2
Fixed crash for getting unmasked text
v1.1.1
Superclass for MaskedEditText was changed to AppCompatEditText, which supports compatible features on older version of the platform
v1.1.0
Ability to get unmasked text (text without mask) was added
v1.0.0
Initial version
Licence
Copyright 2016 Vic Mikhailau
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.