EditText输入校验和一些相关的属性

EditText输入校验,需要对%,_,#这些符号进行限制输入,我是直接通过EditText的addTextChangedListener方法来设置监听的:
private final TextWatcher mTextWatcher = new TextWatcher() {
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
    } 

    public void onTextChanged(CharSequence s, int start, int before, int count) {
    } 

    public void afterTextChanged(Editable s) {
        if (s.length() > 0) {
            int pos = s.length() - 1;
            char c = s.charAt(pos);
            if (c == '#') {//这里限制在字串最后追加# 
                s.delete(pos,pos+1);
                Toast.makeText(MyActivity.this, "Error letter.",Toast.LENGTH_SHORT).show();
            }
        }
    }
}; 

通过设置android:imeOptions来改变软件盘中的部分按键显示:

  1. actionUnspecified  未指定,对应常量EditorInfo.IME_ACTION_UNSPECIFIED.效果:
  2. actionNone 没有动作,对应常量EditorInfo.IME_ACTION_NONE 效果:
  3. actionGo 去往,对应常量EditorInfo.IME_ACTION_GO 效果:
  4. actionSearch 搜索,对应常量EditorInfo.IME_ACTION_SEARCH 效果:
  5. actionSend 发送,对应常量EditorInfo.IME_ACTION_SEND 效果:
  6. actionNext 下一个,对应常量EditorInfo.IME_ACTION_NEXT 效果:
  7. actionDone 完成,对应常量EditorInfo.IME_ACTION_DONE 效果:
  8. 暂时还不知道怎么控制软件不显示那些符号的按键的键盘,我通过设置了inputType属性 android:inputType="textPersonName"但还是没有效果
参考1: http://android.group.iteye.com/group/wiki/2910-android-widget-edittext

参考2:http://bbs.cfan.com.cn/thread-1442999-1-1.html


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值