Android Edittext 开发常见问题总结(焦点、输入、键盘弹出等)
来源:互联网 发布:知乎 单人沙发推荐 编辑:程序博客网 时间:2024/04/27 17:29
Edittext在android的开发中经常需要使用,以下列举其开发中遇到的一些常见情况:
1、焦点得到/失去事件监听
我们需要在android的Edittext得到/失去焦点时,处理一些事件时,需要对EditText对象的Focus进行监听处理。
//定义Edittext mEdt = (EditText) findViewById(R.id.my_edittext);mEdt .setOnFocusChangeListener(mFocusChangeListener);//监听private OnFocusChangeListener mFocusChangeListener = new OnFocusChangeListener() { @Override public void onFocusChange(View arg0, boolean isFocus) { // TODO Auto-generated method stub if(isFocus) { // 此处进行得到焦点时的事件处理 } else { // 此处进行失去焦点时的事件处理 } } };
2、强制失去焦点
在某些情况下,我们不希望进入界面初始化时Edittext自动获取焦点,有一种简便方法:此时我们只需在xml文件中使其强制失去焦点,具体在其父控件中加上:
android:focusable=”true”
android:focusableInTouchMode=”true”
代码如下:
<RelativeLayout android:layout_width="fill_parent" android:layout_height="35dp" android:focusable="true" android:focusableInTouchMode="true" android:orientation="horizontal" > <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <EditText style="@style/EditText" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_toLeftOf="@id/button" android:background="@null" > </EditText></RelativeLayout>
3、输入特殊格式的字符
密码文本框:密码输入是Android应用常用的功能,通过配置EditText的android:password=”true”就可以实现这一密码输入功能
电话输入框:专门输入电话号码的文本框,通过设置android:phoneNumber=”true”就可以把EditText变成只接受电话号码输入的文本框,连软键盘都已经变成拨号专用软键盘了。
纯数字:EditText为我们提供了android:numeric来控制输入的数字类型,一共有三种分别为integer(正整数)、signed(带符号整数)和decimal(浮点数)。
4、Enter键图标
软键盘的Enter键默认显示的是“完成”文本。通过设置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
5、键盘弹出问题
5.1 此处给出Android EditText不弹出输入法焦点问题的总结。
5.2 强制弹出键盘:
mEidText = (EditText) findViewById(R.id.edittext); mEidText.setFocusableInTouchMode(true); mEidText.requestFocus(); Timer timer = new Timer(); timer.schedule(new TimerTask() { public void run() { InputMethodManager inputManager = (InputMethodManager) mEidText.getContext() .getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.showSoftInput(mEidText, 0); } },800);
其他问题,待补充。
- Android Edittext 开发常见问题总结(焦点、输入、键盘弹出等)
- android开发EditText输入时弹出数字输入键盘
- Android中使EditText失去焦点,edittext禁止弹出键盘
- Android中使EditText失去焦点,edittext禁止弹出键盘
- Android中使EditText失去焦点,edittext禁止弹出键盘
- Android中使EditText失去焦点,edittext禁止弹出键盘
- AndroidのEditText失去焦点,edittext禁止弹出键盘
- Android中使EditText失去焦点,edittext禁止弹出键盘
- Android中使EditText失去焦点,edittext禁止弹出键盘
- Android中使EditText失去焦点,edittext禁止弹出键盘
- Android中使EditText失去焦点,edittext禁止弹出键盘
- Android中使EditText失去焦点,edittext禁止弹出键盘
- Android中使EditText失去焦点,edittext禁止弹出键盘
- Android中使EditText失去焦点,edittext禁止弹出键盘
- Android中使EditText失去焦点,edittext禁止弹出键盘
- Android中使EditText失去焦点,edittext禁止弹出键盘
- android editText自动弹出软键盘(输入键盘)
- android强制隐藏键盘(当edittext获得焦点时不弹出键盘)
- [LeetCode 203] Remove Linked List Elements
- 复数
- 配色调色盘
- 关于xib下tableview空出一部分的问题
- NBUT 1218 You are my brother
- Android Edittext 开发常见问题总结(焦点、输入、键盘弹出等)
- Android开发设置软键盘收索键
- c# 线程中更新UI
- AdapterView及子类
- ios开发环境搭建
- c++ 11 新特性
- SQLite学习笔记(1)-安装及其点命令
- 阿里云推荐码(优惠码)可享9折优惠 : KLRG4L、4XGELG
- elf、bin、hex文件互转