在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:FormatEditText开源软件地址:https://gitee.com/dkzwm/FormatEditText开源软件介绍:FormatEditTextEnglish | 中文本库提供3个类以供使用:
特性:
演示程序下载 Demo.apk 快照引入添加如下依赖到你的 build.gradle 文件: repositories { ... maven { url 'https://jitpack.io' }}dependencies { implementation 'com.github.dkzwm:FormatEditText:0.2.0'} 使用在Xml中配置<me.dkzwm.widget.fet.FormattedEditText android:id="@+id/formattedEditText_simple" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="phone" android:maxLength="13" app:fet_clearDrawable="@drawable/icon_clear" app:fet_drawableGravity="fet_center" app:fet_drawablePadding="4dp" app:fet_formatStyle="344" app:fet_mode="mode_simple" app:fet_placeholder="-" /><me.dkzwm.widget.fet.FormattedEditText android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="phone" android:maxLength="19" app:fet_clearDrawable="@drawable/icon_clear" app:fet_drawableGravity="fet_center" app:fet_drawablePadding="4dp" app:fet_formatStyle="+(86)-***-****-****" app:fet_mark="*" app:fet_mode="mode_complex" /><me.dkzwm.widget.fet.FormattedEditText android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="phone" android:maxLength="19" app:fet_clearDrawable="@drawable/icon_clear" app:fet_drawableGravity="fet_center" app:fet_drawablePadding="4dp" app:fet_emptyPlaceholder="_" app:fet_formatStyle="+(86)-000-0000-0000" app:fet_mode="mode_mask" app:fet_showHintWhileEmpty="true" /><me.dkzwm.widget.fet.FormattedEditText android:layout_width="match_parent" android:layout_height="wrap_content" android:digits="0123456789X" android:maxLength="22" app:fet_clearDrawable="@drawable/icon_clear" app:fet_drawableGravity="fet_center" app:fet_drawablePadding="4dp" app:fet_formatStyle="000 000 0000 0000 000*" app:fet_hintText="100 000 2020 0101 000X" app:fet_mode="mode_hint" app:fet_showHintWhileEmpty="false" /><me.dkzwm.widget.fet.MaskNumberEditText android:layout_width="match_parent" android:layout_height="wrap_content" app:fet_clearDrawable="@drawable/icon_clear" app:fet_drawableGravity="fet_center" app:fet_drawablePadding="4dp" app:fet_autoFillNumbers="false" app:fet_currencySymbol="¥" app:fet_decimalLength="2" app:fet_showThousandsSeparator="true" /> Java代码配置FormattedEditText.Config.create() .mode(FormattedEditText.MODE_SIMPLE) //简单模式 .formatStyle("344") //格式化样式 .placeholder(' ') //占位符 .config(editText);FormattedEditText.Config.create() .mode(FormattedEditText.MODE_COMPLEX) //组合模式 .formatStyle("+(86)-***-****-****") //格式化样式 .mark('*') //标记符 .config(editText);FormattedEditText.Config.create() .mode(FormattedEditText.MODE_MASK) //掩码匹配模式 .formatStyle("+(86)-000-0000-0000") //格式化样式 .emptyPlaceholder('_') //空白数据占位符 .showHintWhileEmpty(true) //是否清除数据后显示默认提示文字(android:hint),开启后不会用空白数据占位符填充数据位 .config(editText);FormattedEditText.Config.create() .mode(FormattedEditText.MODE_HINT) //提示模式 .formatStyle("000 000 0000 0000 000X") //格式化样式 .maskFilter("X", new FormattedEditText.Matcher() { @Override public boolean hasMatch(String previousText, String value) { return TextUtils.isDigitsOnly(value) || value.toUpperCase().equals("X"); } })//自定义掩码匹配 .maskFilter("0", new FormattedEditText.Matcher() { @Override public boolean hasMatch(String previousText, String value) { return TextUtils.isDigitsOnly(value); } })//自定义掩码匹配 .hintText("100 000 2020 0101 000X") //提示文字,不同于默认提示文字(android:hint),会在输入字符后依然显示,必须和格式化样式格式一致 .hintColor(Color.GRAY) //提示文字颜色 .showHintWhileEmpty(true) //是否清除数据后显示默认提示文字(android:hint),开启后不会用空白数据占位符填充数据位 .config(editText);MaskNumberEditText editText = new MaskNumberEditText(context);editText.setShowThousandsSeparator(true);//是否显示千位分隔符`,`editText.setAutoFillNumbers(true);//是否自动填充小数,如设置小数保留2位,那么当位数不足时会自动填充`0`editText.setDecimalLength(2);//小数位长度editText.setCurrencySymbol("¥");//设置货币符号,不设置即不显示editText.setMaxNumberValue(6666.66)//指定能输入的最大数值 Xml属性ClearEditText
FormattedEditText
MaskNumberEditText
掩码
样式中的其他字符则会原样显示。如果需要原样显示这4个特殊字符,则需要使用转义符 感谢License-------- Copyright (c) 2017 dkzwmPermission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in allcopies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, 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 THESOFTWARE. |
请发表评论