EditText使用笔记
来源:互联网 发布:怎么更改淘宝店名 编辑:程序博客网 时间:2024/05/19 07:07
1、替换光标
android:textCursorDrawable="@drawable/shape_cusor" xml文件:<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <size android:width="1dp" /> <solid android:color="@color/civ_designer" /></shape>
2、显示或隐藏EditText的hint文字说明
mEtDetail.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View view, boolean hasFocus) { //显示或隐藏EditText的hint文字说明 changeHint((EditText) view, hasFocus); } }); private void changeHint(EditText view, boolean hasFocus) { EditText textView = view; String hint; if (hasFocus) { //隐藏输入提示文字 hint = textView.getHint().toString(); textView.setTag(hint); textView.setHint(""); } else { //显示输入提示文字 hint = textView.getTag().toString(); textView.setHint(hint); } }
3、限制输入框的输入字数
mEtDetail.addTextChangedListener(new TextWatcher() {long time;@Overridepublic void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {}@Overridepublic void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {}@Overridepublic void afterTextChanged(Editable editable) { //限制需求描述输入字数 String trim = mEtDetail.getText().toString().trim(); if(trim!=null&&trim.length()>600){ String str=trim.substring(0,600); mEtDetail.setText(str); mEtDetail.setSelection(str.length()); long l = System.currentTimeMillis(); if(l-time>10000){ //超过十秒才能再次提示 ToastUtil.show("输入字数不能超过600字"); time=l; } }}});
4、判断字符串是否为纯数字
public boolean isNum(String str){ Pattern pattern = Pattern.compile("[0-9]*"); Matcher isNum = pattern.matcher(str); return isNum.matches(); }
5、判断手机号码是否正确
/** * 大陆号码或香港号码均可 */ public static boolean isPhoneLegal(String str)throws PatternSyntaxException { return isChinaPhoneLegal(str) || isHKPhoneLegal(str); } /** * 大陆手机号码11位数,匹配格式:前三位固定格式+后8位任意数 * 此方法中前三位格式有: * 13+任意数 * 15+除4的任意数 * 18+除1和4的任意数 * 17+除9的任意数 * 147 */ public static boolean isChinaPhoneLegal(String str) throws PatternSyntaxException { String regExp = "^((13[0-9])|(15[^4])|(18[0,2,3,5-9])|(17[0-8])|(147))\\d{8}$"; Pattern p = Pattern.compile(regExp); Matcher m = p.matcher(str); return m.matches(); } /** * 香港手机号码8位数,5|6|8|9开头+7位任意数 */ public static boolean isHKPhoneLegal(String str)throws PatternSyntaxException { String regExp = "^(5|6|8|9)\\d{7}$"; Pattern p = Pattern.compile(regExp); Matcher m = p.matcher(str); return m.matches(); }
0 0
- EditText使用笔记
- Android学习笔记13:EditText的使用
- Android学习笔记 EditText的简单使用
- Android学习笔记13:EditText的使用
- editText 笔记
- EditText笔记
- EditText使用
- 使用SpannableString+EditText图文混排仿为知笔记编辑框
- Android EditText 学习笔记
- 下划线EditText-UnderlineEditText-笔记
- 笔记104--ListView+EditText
- TextView-EditText笔记
- Android EditText学习笔记
- EditText使用详解-EditText基础说明
- Android EditText使用
- EditText使用详解
- EditText使用详解
- EditText使用详解
- html5学习笔记(三)(摘抄讲义加部分理解)
- zerorpc-python官方入门
- UTF-8和unicode的关系
- 2.安卓基础——服务器web
- keeplived+Nginx+Redis实现Tomcat的session共享
- EditText使用笔记
- AbstractWizardFormController
- 跑 Monkey
- python基础语法(6) 函数1
- Java 获取当前时间往前推最近12月“年-月”格式的时间,方便统计使用
- Android Studio相见恨晚的操作锦集
- 多次复制可粘贴小工具
- 文本溢出与国际化
- 虚拟机自适应屏幕的分辨率(以xp为例)