EditText

1.监听器

addTextChangedListener :文本变化观察者
setOnEditorActionListener: 键盘回车事件

2.常用属性

  • android:password=”true” 这条可以让EditText显示的内容自动为星号,输入时内容会在1秒内变成*字样。
  • android:numeric=”true” 这条可以让输入法自动变为数字输入键盘,同时仅允许0-9的数字输入
  • android:capitalize=”abcde” 这样仅允许接受输入abcde,一般用于密码验证
  • android:hint=”密码” 设置显示的提示信息
  • android:maxLine=”2” 设置最多多少行
  • android:inputType=”number” 输入类型
  • android:imeOptions=”actionDone” 键盘回车的类型

        下面列出比较经常用到的几个属性以及替换的文本外观:  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 

3.输入完成,关闭输入法

有时候输入完成,需要关闭输入法,不然用户体验效果不好

    etQueryPhone.setOnEditorActionListener(new TextView.OnEditorActionListener() {        @Override        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {            //关闭输入法            InputMethodManager inputMethodManager = (InputMethodManager)                    QueryAddressActivity.this.getSystemService                            (Context.INPUT_METHOD_SERVICE);            inputMethodManager.hideSoftInputFromWindow(etQueryPhone.getWindowToken(), 0);            return true;        }    });

4.抖动EditText

1.在res/anim下创建shake.xml文件

<?xml version="1.0" encoding="utf-8"?>    

2.在res/anim下创建cycle_7.xml

<?xml version="1.0" encoding="utf-8"?>    

3.使用时

Animation shake = AnimationUtils.loadAnimation(QueryAddressActivity.this, R.anim.shake);etQueryPhone.startAnimation(shake);

更多相关文章

  1. Android(安卓)控制EditText输入为英文或数字
  2. Android对弹出输入法界面影响app界面布局
  3. Android(安卓)cocos2d-x开发(三)之创建Android工程和编译
  4. 如何启动Android(安卓)SDK 1.5模拟器
  5. EditText的输入限制设置
  6. Android(安卓)EditText控件使用
  7. android 输入法弹出键盘把listview顶上去,保留顶部标题栏位置不动
  8. android edittext 限制输入框小数位数
  9. Android禁止EditText弹出输入法

随机推荐

  1. 浅析Context及可能带来的内存泄漏问题
  2. Android 事件处理(—)(附源码)
  3. iPhone和Android智能手机浏览器判断分辨
  4. android 开关按钮
  5. 基于移动平台的多媒体框架——移植ffmpeg
  6. Android中抓取手机视频流数据。
  7. android的Activity窗口模式
  8. Android 9.0 关于ACTION_CALL无权限导致
  9. 在Qt for Android中添加.a或so库文件
  10. 入门:Android 文档的阅读顺序