EditView

1、密码

密码小眼睛(显示密码和隐藏密码)可以在密码EditView控件外层加TextInputLayout ,不需要自己手动去写。

在app下的 build.gradle 中引入
    compile 'com.android.support:appcompat-v7:25.0.0'
    compile 'com.android.support:design:25.0.0'

在布局文件中使用

<android.support.design.widget.TextInputLayout
  android:id="@+id/id_pwd_Layout"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  app:passwordToggleEnabled="true"
  >
  <EditText
  android:id="@+id/id_et_pwd"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:hint="@string/edt_pwd_hint"
  android:maxLines="1"
  android:inputType="textPassword" />
 </android.support.design.widget.TextInputLayout>
ps: 当输入类型设置为android:inputType="textPassword"时(或textWebPassword或numberPassword),app:passwordToggleEnabled="true"才有效,才会出现小眼睛。就算不设置app:passwordToggleEnabled="true"只要输入类型设置为textWebPassword或numberPassword或textPassword一样会有小眼睛。输入类型是textVisiblePassword时,不会出现小眼睛,这个值本身就明确表示显示密码。
感谢以下两篇博文的博主:
点击打开链接http://www.jb51.net/article/102273.htm
点击打开链接https://segmentfault.com/a/1190000009282096
点击打开链接http://www.jianshu.com/p/de9c19d73450
 
2、android:inputType常用取值
    android:inputType="number"//数字格式
    android:inputType="numberSigned"//有符号数字格式
    android:inputType="numberDecimal"//可以带小数点的浮点格式
    android:inputType="phone"//拨号键盘
    android:inputType="datetime"//日期+时间格式
    android:inputType="date"//日期键盘
    android:inputType="time"//时间键盘
<EditText
            android:id="@+id/id_et"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:maxLines="1"
            android:imeOptions="actionNext"
            android:imeActionLabel="下一个"
            android:layout_weight="1"
            android:inputType="numberDecimal"
            android:maxLength="5"
            android:textSize="16dp"
            android:hint="5位(算上小数点5位)"
            />
这里只收录了数值类型,文本类型等类型请查看链接
点击打开链接 http://blog.csdn.net/xqf222/article/details/9789143
3、限制条件setFilters
//实现功能:输入框mEdit中限输入5位(算上小数点5位),小数点后只允许有1位小数
	private int mDecimalNumber = 1;//小数点后的位数  1表示小数点后一位(如0.1)
	EditText mEdit=(EditText)findViewById(R.id.id_et);
        mEdit.setFilters(new InputFilter[]{new InputFilter() {
            @Override
            public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
                String lastInputContent = dest.toString();
                int sourceLenth = lastInputContent.length();
                if (sourceLenth >= 5) {//限定只能输入5位(包括小数点 如123.5)
                    return "";
                }
                if (lastInputContent.contains(".")) {//限制小数点后数据位数
                    int index = lastInputContent.indexOf(".");
                    if (dend - index >= mDecimalNumber + 1) {
                        return "";
                    }
                }
                return null;
            }
        }});
 
方法filter返回空字符串,表示匹配不成功,返回null表示匹配成功
source新输入的字符串
start新输入的字符串起始下标,一般为0
end新输入的字符串终点下标,一般为source长度-1
dest输入之前文本框内容
dstart原内容起始坐标,一般为0
dend原内容终点坐标,一般为dest长度-1
点击打开链接http://blog.csdn.net/vqqyuan/article/details/44676379
点击打开链接http://blog.csdn.net/yichenandanxia/article/details/50914089
 
4、禁止默认获取焦点

在EditText的父控件中设置如下代码:

android:focusable="true"  

android:focusableInTouchMode="true"

这样就把EditText默认获取焦点的行为截断


感谢以上博文的博主,谢谢各位!如有不妥的地方,请各位博主评论区留言,本人看到会立刻处理。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值