Android EditText常见方法总结
2016-01-21 00:00
543 查看
1、设置焦点监听事件
et.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View view, boolean hasFocus) { if(hasFocus){ //有焦点 }else { //无焦点 } } });
2、设置键盘监听事件
et.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View view, int keycode, KeyEvent keyEvent) { if (keycode == KeyEvent.KEYCODE_ENTER) { //回车事件 } return false; //返回false会继续执行回车换行,返回true不会执行回车换行 } }); et.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) { // 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 效果: return false; } });
3、监听键盘响应事件
et.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { // 输入内容之前 } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { // 输入内容的时候 } @Override public void afterTextChanged(Editable editable) { // 输入内容之后 } });
4、限制输入的类型
*在布局文件中设置<EditText android:id="@+id/variableValue" ...... android:inputType="number" />
*在代码中设置
et.setInputType(inputType);
相关的参数:
相关参数
5、默认不要焦点
android:focusable="true" android:focusableInTouchMode="true"
相关文章推荐
- Android中EditText+Button组合导致输入板无法收起的原因分析及解决办法
- Android编程开发之EditText中不输入特定字符会显示相关提示信息的方法
- 解决EditText、ListView以及GridView同时使用,输入法自动跳出来的方法
- Android如何自定义EditText下划线?
- Android编程开发之EditText中inputType属性小结
- android同时控制EditText输入字符个数和禁止特殊字符输入的方法
- Android实现EditText控件禁止输入内容的方法(附测试demo)
- Android中EditText实现不可编辑解决办法
- Android编程实现在自定义对话框中获取EditText中数据的方法
- Android中EditText光标在4.0中的bug及解决方法
- Android实现EditText中添加和删除bitmap的方法
- Android编程实现监听EditText变化的方法
- Android文本输入框(EditText)输入密码时显示与隐藏
- Android编程中EditText限制文字输入的方法
- android基础教程之android的listview与edittext冲突解决方法
- Android实现EditText内容保存为Bitmap的方法
- Android定制自己的EditText轻松改变底线颜色
- Android EditText限制输入字数的方法
- Android编程开发之EditText实现输入QQ表情图像的方法
- Android中EditText和AutoCompleteTextView设置文字选中颜色方法