Android EditText的设置
来源:互联网 发布:Java微信公众号web开发 编辑:程序博客网 时间:2024/05/11 23:53
1、输入法Enter键图标的设置:
软键盘的界面替换只有一个属性android:imeOptions,这个属性的可以取的值有normal,actionUnspecified,actionNone,actionGo,actionSearch,actionSend,actionNext,actionDone,例如当值为actionNext时enter键外观变成一个向下箭头,而值为actionDone时enter键外观则变成了“完成”两个字。
我们也可以重写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
(EditorInfo.inputType & EditorInfo.TYPE_CLASS_MASK)可以是许多不同的值,包括:
TYPE_CLASS_NUMBER
TYPE_CLASS_DATETIME
TYPE_CLASS_PHONE
TYPE_CLASS_TEXT
2、事件捕捉处理:
可以通过setOnEditorActionListener设置事件处理。
final EditText input = new EditText(this); input.setSingleLine(true); //android:singleLine=”true” input.setImeOptions(EditorInfo.IME_ACTION_SEND); input.setInputType(InputType.TYPE_CLASS_TEXT |InputType.TYPE_TEXT_VARIATION_PASSWORD); input.setOnEditorActionListener(new TextView.OnEditorActionListener() { public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { Log.d(TAG, ""+actionId+","+event); if (actionId==EditorInfo.IME_ACTION_SEND ||(event!=null&&event.getKeyCode()== KeyEvent.KEYCODE_ENTER)) { //do something; return true; } return false; } });
3、editor密码隐藏,怎么写?
有2种方法处理:
代码方法:input.setInputType(InputType.TYPE_CLASS_TEXT |InputType.TYPE_TEXT_VARIATION_PASSWORD);
layout配置方法:android:inputType="textPassword"
4、activity加载完成后,edit输入框会自动弹出输入法,可以通过以下代码屏蔽:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
5、设置EditText始终不弹出软件键盘
例:EditText edit=(EditText)findViewById(R.id.edit);
edit.setInputType(InputType.TYPE_NULL);
6、让 EditText失去焦点,使用EditText的clearFocus方法
例如:EditText edit=(EditText)findViewById(R.id.edit);
edit.clearFocus();
7、EditText默认不弹出软件键盘
在 AndroidMainfest.xml中选择activity,设置windowSoftInputMode属性为 adjustUnspecified|stateHidden
< activity android:name=".Main"android:label="@string/app_name"android:windowSoftInputMode="adjustUnspecified|stateHidden"android:configChanges="orientation|keyboardHidden">< intent-filter>< action android:name="android.intent.action.MAIN" />< category android:name="android.intent.category.LAUNCHER" />< /intent-filter>< /activity>
- Android EditText的设置
- Android EditText的设置
- Android EditText的设置
- Android EditText的设置
- Android EditText的设置
- Android EditText的设置
- Android EditText的设置
- Android EditText的设置
- Android EditText的设置
- Android EditText的设置
- Android EditText的设置
- Android EditText的设置
- Android EditText的设置
- Android EditText的设置
- Android EditText的设置
- Android EditText的设置
- Android EditText的设置
- Android EditText的设置
- 【Loadrunner】解决controller中负载机连接成功,但执行场景时无法正常执行问题
- Problem 025——UVa 253 - Cube painting
- Mysql HA-Install Keepalived+LVS+Mysql(双主) On Redhat 6.3
- 在使用shape的同时,用代码修改shape的颜色属性
- 让年轻程序员少走弯路的14个忠告
- Android EditText的设置
- 继承CWnd自绘按钮
- JQuery判断数组中是否包含某个元素$.inArray("js", arr);
- Gsoap回传字符串中文乱码解决方案
- HTML5 drawImage 使用问题
- MATLAB图像处理工具箱
- SDUT_2015寒假集训_BFS&DFS_J-Catch That Cow
- 讨论:怎样做需求?
- Android控件ActionBar浅析及适配2.x的方法介绍