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来改变软件盘中的部分按键显示:
- actionUnspecified 未指定,对应常量EditorInfo.IME_ACTION_UNSPECIFIED.效果:
- actionNone 没有动作,对应常量EditorInfo.IME_ACTION_NONE 效果:
- actionGo 去往,对应常量EditorInfo.IME_ACTION_GO 效果:
- actionSearch 搜索,对应常量EditorInfo.IME_ACTION_SEARCH 效果:
- actionSend 发送,对应常量EditorInfo.IME_ACTION_SEND 效果:
- actionNext 下一个,对应常量EditorInfo.IME_ACTION_NEXT 效果:
- actionDone 完成,对应常量EditorInfo.IME_ACTION_DONE 效果:
- 暂时还不知道怎么控制软件不显示那些符号的按键的键盘,我通过设置了inputType属性 android:inputType="textPersonName"但还是没有效果
参考2:http://bbs.cfan.com.cn/thread-1442999-1-1.html