当前位置: 首页 > 软件库 > 手机/移动开发 > >

input-mask-android

User input masking library repo.
授权协议 MIT License
开发语言 Kotlin
所属分类 手机/移动开发
软件类型 开源软件
地区 不详
投 递 者 宗政坚白
操作系统 Android
开源组织
适用人群 未知
 软件概览

Input Mask

Direct input

More GIFs [~3 MB] Direct input Direct input Direct input
Direct input Direct input

Migration Guide: v.6

This update brings breaking changes. Namely, the autocomplete flag is now a part of the CaretGravity enum, thus the Mask::apply call is now single-argument, as all the necessary information is included into the CaretString structure.

v.6 introduces the «autoskip» feature, which allows the cursor to jump over formatting blocks of symbols in the middle of the text as if they were a single char when hitting Backspace, and this feature also allows to trim formatting characters on backspacing at the end of the line.

Make sure to take a look at our CHANGELOG.

Description

Input Mask is an Android & iOS native library allowing to format user input on the fly.

The library provides you with a text field listener; when attached, it puts separators into the text while user types it in, and gets rid of unwanted symbols, all according to custom predefined pattern.

This allows to reformat whole strings pasted from the clipboard, e.g. turning pasted 8 800 123-45-67 into
8 (800) 123 45 67.

Each pattern allows to extract valuable symbols from the entered text, returning you the immediate result with the text field listener's callback when the text changes. Such that, you'll be able to extract 1234567 from 8 (800) 123 45 67 or 19991234567 from 1 (999) 123 45 67 with two different patterns.

All separators and valuable symbol placeholders have their own syntax. We call such patterns "masks".

Mask examples:

  1. International phone numbers: +1 ([000]) [000] [00] [00]
  2. Local phone numbers: ([000]) [000]-[00]-[00]
  3. Names: [A][-----------------------------------------------------]
  4. Text: [A…]
  5. Dates: [00]{.}[00]{.}[9900]
  6. Serial numbers: [AA]-[00000099]
  7. IPv4: [099]{.}[099]{.}[099]{.}[099]
  8. Visa card numbers: [0000] [0000] [0000] [0000]
  9. MM/YY: [00]{/}[00]
  10. UK IBAN: GB[00] [____] [0000] [0000] [0000] [00]

Questions & Issues

Check out our wiki for further reading.
Please also take a closer look at our Known issues section before you incorporate our library into your project.

For your bugreports and feature requests please file new issues as usually.

Should you have any questions, search for closed issues or open new ones at StackOverflow with the input-mask tag.

We also have a community-driven cookbook of recipes, be sure to check it out, too.

Installation

Gradle

Make sure you've added Kotlin support to your project.

repositories {
    jcenter()
}

dependencies {
    implementation 'com.redmadrobot:input-mask-android:6.0.0'
    
    implementation 'org.jetbrains.kotlin:kotlin-stdlib:$latest_version'
}

Known issues

InputMask vs. NoClassDefFoundError

java.lang.NoClassDefFoundError: Failed resolution of: Lkotlin/jvm/internal/Intrinsics;

Receiving this error might mean you haven't configured Kotlin for your Java only project. Consider explicitly adding the following to the list of your project dependencies:

implementation 'org.jetbrains.kotlin:kotlin-stdlib:$latest_version'

— where latest_version is the current version of kotlin-stdlib.

InputMask vs. android:inputType and IndexOutOfBoundsException

Be careful when specifying field's android:inputType.The library uses native Editable variable received on afterTextChange event in order to replace text efficiently. Because of that, field's inputType is actually considered when the library is trying to mutate the text.

For instance, having a field with android:inputType="numeric", you cannot put spaces and dashes into the mentioned Editable variable by default. Doing so will cause an out of range exception when the MaskedTextChangedListener will try to reposition the cursor.

Still, you may use a workaround by putting the android:digits value beside your android:inputType; there, you should specify all the acceptable symbols:

<EditText
    android:inputType="number"
    android:digits="0123456789 -."
    ... />

— such that, you'll have the SDK satisfied.

Alternatively, if you are using a programmatic approach without XML files, you may consider configuring a KeyListener like this:

editText.setInputType(InputType.TYPE_CLASS_NUMBER);
editText.setKeyListener(DigitsKeyListener.getInstance("0123456789 -.")); // modify character set for your case, e.g. add "+()"

InputMask vs. autocorrection & prediction

(presumably fixed by PR50)

Symptoms:

  • You've got a wildcard template like [________], allowing user to write any kind of symbols;
  • Cursor jumps to the beginning of the line or to some random position while user input.

In this case text autocorrection & prediction might be a root cause of your problem, as it behaves somewhat weirdly in case when field listener tries to change the text during user input.

If so, consider disabling text suggestions by using corresponding input type:

<EditText
    ...
    android:inputType="textNoSuggestions" />

Additionally be aware that some of the third-party keyboards ignore textNoSuggestions setting; the recommendation is to use an extra workaround by setting the inputType to textVisiblePassword.

InputMask vs. android:textAllCaps

Kudos to Weiyi Li for reporting this issue

Please be advised that android:textAllCaps is not meant to work with EditText instances:

This setting will be ignored if this field is editable or selectable.

Enabling this setting on editable and/or selectable fields leads to weird and unpredictable behaviour and sometimes even crashes. Instead, consider using android:inputType="textCapCharacters" or workaround by adding an InputFilter:

final InputFilter[] filters = { new InputFilter.AllCaps() };
editText.setFilters(filters);

Bare in mind, you might have to befriend this solution with your existing android:digits property in case your text field accepts both digits and letters.

References

The list of projects that are using this library which were kind enough to share that information.

Feel free to add yours below.

Special thanks

These folks rock:

License

The library is distributed under the MIT LICENSE.

  • 看到了就记一记啊 前言 android:inputType 是开发中非常常用的字段了,但你知道他都有哪些取值吗? 先一起看一下吧,然后我们逐个说一下。 inputType 首先,要避免一个误区,这个是 输入类型,而不是显示类型, 所以在有些类型的解释上可能要注意这个问题。它更多的是影响了键盘或者其它识别的输入问题,比如候选项,比如实时的纠错和补全,或者其它数值问题。 当然,不可避免的它从输入的角度

  • 在Android开发过程中,我们经常使用到EditText控件,并且会根据各种需求设置它的输入类型。设置EditText输入类型主要有两种方法,一种是使用EditText的setInputType()方法,另一种是在布局文件中使用android:inputType属性来设置。 下面将介绍这两种方法: (1)使用EditText的setInputType()方法设置输入类型: ''' '''' Ed

  • public class MaskableFrameLayout extends FrameLayout { //Constants private static final String TAG = "MaskableFrameLayout"; private static final int MODE_ADD = 0; private static final int MODE_CLEAR =

  • android - 在2.3上使用Done SoftInput动作标签的多行EditText 有没有办法让多线InputType.TYPE_TEXT_FLAG_MULTI_LINE出现并在Android 2.3上使用IME Action Label“Done”? 在Android 2.2中,这不是问题,输入按钮显示IME操作标签“完成”(InputType.TYPE_TEXT_FLAG_MULTI

  • (用华为P30带你看安卓) 简介:华为P30,Android 9.0(API 28) 如果你在从事安卓的开发,如果你苦于看不懂android 的输入逻辑,如果你想找到更好Android 调试工具,那么强烈建议你看完本文。如果你那么做了,你会了解dumpsys input ,你会了解 input事件的派发逻辑,你会对Android 更感兴趣; HWELE:/ $ dumpsys input INPU

  • 使用详解 xxxxxxxx:/ # getevent -h Usage: getevent [-t] [-n] [-s switchmask] [-S] [-v [mask]] [-d] [-p] [-i] [-l] [-q] [-c count] [-r] [device] -t: show time stamps -显示事件的发生时间 -n: don't print newli

  • android平台2.3.4,发现插上usb鼠标和键盘开机,那么都能正常使用,一旦拔出以后再插回去,就不能使用了。 首先检测/dev/input下的设备节点是否正常,发现拔出和插入设备,节点文件都能正常删除和创建。 # ls /dev/input/ -al total 8 drwxrwxrwx    2 root     root          4096 Feb 29  2012 ./ drw

  • Android Input系统9 INotify与Epoll机制         熟悉或者了解过input机制的,知道在native层会有EventHub去接受底层input上报的数据,下面的例子主要从EventHub中拆解出来的,能简单实现(1).检测是否有新的input设备插入<在dev/input中新增文件测试>,(2).检测是否有新的input_event上报,        inotif

 相关资料
  • mask is a CLI task runner which is defined by a simple markdown file. It searches for a maskfile.md in the current directory which it then parses for commands and arguments. A maskfile.md is both a hu

  • Weex 弹层组件,可定制内容 Demo 使用方法 <template> <div> <div @click="openMask"> <text>点击弹出动画面板</text> </div> <div @click="openNoAnimationMask"> <text>点击弹出无动画面板</text> </div> <wxc-

  • SVG MASK 蒙版工作原理 设计师或者会用Sketch、Photoshop一类设计工具的朋友应该都了解蒙版(mask)这个东西。接下来我先以Photoshop为例,简单解释蒙版的工作原理。 上图中创建了两个图层——蓝色的背景和红色的前景,并且在红色前景上应用了一个蒙版(右边红圈)。正常情况下红色前景应该完全遮盖住蓝色背景,但是请注意红圈中的蒙版,在这个蒙版上画了一个黑色的矩形。 蒙版中黑色代表

  • ngx-mask You can also try our NGX LOADER INDICATOR.You can also try our NGX COPYPASTE. You can see the full documentation with examples Installing $ npm install --save ngx-mask Quickstart Import ngx-m

  • ⚠️ This library is not maintained. Pull-requests and issues are not monitored. Alternatives to text-mask include: https://github.com/uNmAnNeR/imaskjs https://github.com/JsDaddy/ngx-mask If you know ot

  • 实现界面放大镜功能。手指在屏幕上移动,手指所在位置的上方出现放大镜,显示手指所在位置部分的放大图像。可以放大界面上任意控件。 [Code4App.com]