原创文章,如有转载,请注明出处:http://blog.csdn.net/myth13141314/article/details/72926672
带图标的提示比较快捷的方式是使用EditText自己的属性来设置
android:drawableLeft="@drawable/icon_search"(放大镜图标)
android:drawablePadding="10dp"(设置图标的间距)
EditText过滤特殊字符,如换行符/回车等
- 可以给EditText设置监听,过滤掉回车/换行的按钮事件
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
return true;//消耗事件
}
});
- 也可以将输入的字符进行过滤
/**
* 过滤特殊字符
* @param str
* @return
*/
public static String replaceBlank(String str) {
String dest = "";
if (str!=null) {
Pattern p = Pattern.compile("\\s*|\t|\r|\n");(空格/制表/回车/换行)
Matcher m = p.matcher(str);
dest = m.replaceAll("");
}
return dest;
}