Step 1. Add the JitPack repository to your build file
Add it in your root build.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.arefbhrn:maskededittext:1.0.0'
}
<dependency>
<groupId>com.github.arefbhrn</groupId>
<artifactId>maskededittext</artifactId>
<version>1.0.0</version>
</dependency>
libraryDependencies += "com.github.arefbhrn" % "maskededittext" % "1.0.0"
:dependencies [[com.github.arefbhrn/maskededittext "1.0.0"]]
A library to achieve masked TextView for both RTL and LTR texts.
This project derives from egslava/edittext-mask, but it's been adapted for AndroidX
:
So it allows you to use masks for phones, urls, etc.
Enjoy!
Gradle
dependencies {
implementation 'com.github.arefbhrn:MaskedEditText:1.0.0'
}
Add xmlns:app="http://schemas.android.com/apk/res-auto"
to your layout xml root:
<com.arefbhrn.maskededittext.MaskedEditText
android:id="@+id/phone_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="phone"
android:typeface="monospace"
android:hint="1234567890"
app:allowed_chars="1234567890"
app:mask="+44(###)###-##-##"
app:keep_hint="true" />
Where mask
is the input mask you want and '#' is an editable position (will be replaced by a whitespace on screen).
You can optionally set the representation character (in case you don't want to use '#'):
<com.arefbhrn.maskededittext.MaskedEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
mask:mask="ccc.ccc.ccc-cc"
mask:char_representation="c" />
You can also use the it programmatically:
MaskedEditText editText = (MaskedEditText) findViewById(R.id.my_edit_text)
// Setting the representation character to '$'
editText.setCharRepresentation('$');
// Get the representation character
editText.getCharRepresentation();
// Setting the mask
editText.setMask("##/##/####");
// Logging the mask
editText.getMask();
// Get typed text without mask chars
editText.getRawText();
// Keep hint showing
editText.setKeepHint(true);
If you have a better idea or way on this project, please let me know, thanks :)
This project is licensed under the Apache 2.0 License - see the LICENSE.md file for details