0 Star 0 Fork 5

Danny / FormatEditText

forked from dkzwm / FormatEditText 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
README.md 3.73 KB
一键复制 编辑 原始数据 按行查看 历史
dkzwm 提交于 2018-03-23 09:48 . Ready to release version 0.0.5.3

FormatEditText

English | 中文

FormatEditText可以用来当做号码格式化文本输入框使用, 可以用来作为格式化手机号码、格式化身份证号码、格式化银行卡号码等.

  • 例如:指定模式为MODE_SIMPLE, 样式为344, 占位符为-, 手动依次输入13012345678, 那么最终会格式化为130-1234-5678, 且中间删除更改会自动补位.
  • 例如:指定样式为MODE_COMPLEX, 样式为***-****-****, 标记符为*, 手动依次输入13012345678, 那么最终会格式化为130-1234-5678, 且中间删除更改会自动补位.

特性:

  • 支持配置格式化样式
  • 支持粘贴且光标自动跟随
  • 自动填充删除占位符

演示程序

下载 Demo.apk

快照

使用

Gradle

repositories {  
    ...
    maven { url 'https://jitpack.io' }  
}

dependencies {  
    compile 'com.github.dkzwm:FormatEditText:0.0.5.3'
}

在Xml中配置

//组合模式
<me.dkzwm.widget.fet.FormattedEditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:fet_formatStyle="+(**)-***-****-****"
    app:fet_mark="*"
    app:fet_mode="mode_complex"/>

//简单模式
<me.dkzwm.widget.fet.FormattedEditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:fet_formatStyle="344"
    app:fet_mode="mode_simple"
    app:fet_placeholder=" "/>

Java代码配置

//简单模式
FormattedEditText editText = findViewById(R.id.formattedEditText);
editText.setMode(FormattedEditText.MODE_SIMPLE);
editText.setFormatStyle("344");
editText.setPlaceholder(" ");(输入13012345678,格式化后为:130 1234 5678)
//组合模式
editText.setMode(FormattedEditText.MODE_SIMPLE);
editText.setMark("*");
editText.setFormatStyle("+(**)-***-****-****");(输入8613012345678,格式化后为:+(86)-130-1234-5678)

Xml属性

名称 类型 描述
fet_mode enum 指定模式,支持MODE_SIMPLE(简单模式)和MODE_COMPLEX(组合模式)
fet_formatStyle string 指定格式化样式,当fet_modeMODE_SIMPLE时,格式只能是纯数字, fet_modeMODE_COMPLEX时,格式为任意格式且需要指定fet_mark属性,如果不指定那么默认为*
fet_mark string 指定标记符,仅当fet_modeMODE_COMPLEX时需要设置,且长度必须为1(默认:*
fet_placeholder string 指定占位符,仅当fet_modeMODE_SIMPLE时需要设置,且长度必须为1(默认:

License

--------

	Copyright (c) 2017 dkzwm

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Android
1
https://gitee.com/longzekai/FormatEditText.git
git@gitee.com:longzekai/FormatEditText.git
longzekai
FormatEditText
FormatEditText
master

搜索帮助