android软键盘的事件响应:android EditText inputType 及 android:imeOptions=”actionDone”
来源:互联网 发布:win10 mysql卸载 编辑:程序博客网 时间:2024/05/17 03:48
如果布局中包含多个EditText,可以为每个EditText控件设置android:singleLine=”true”,弹出的软盘输入法中回车键为next,直到最后一个获取焦点后显示为Done。点击Done后,隐藏软键输入盘。将EditText的imeOptions属性设置android:imeOptions=”actionDone”,则不管是不是最后一个EditText,点击回车键即隐藏输入法。
监听Enter的事件,编写Enter的事件响应。设置文本框的OnKeyListener,当keyCode ==KeyEvent.KEYCODE_ENTER的时候,表明Enter键被按下,就可以编写自己事件响应功能了。
XML文件如下:
<EditText
android:id=
"@+id/editTextId"
android:layout_width=
"fill_parent"
android:layout_height=
"50dp"
android:imeOptions=
"actionDone"
android:hint=
"@string/task_new_one"
android:textSize=
"15sp"
android:singleLine=
"true"
android:paddingLeft=
"5dp"
android:layout_gravity=
"center"
android:background=
"@drawable/rectangle"
android:inputType=
"text"
>
</EditText>
把EditText的Ime Options属性设置成不同的值,Enter键上可以显示不同的文字或图案。
actionNone : 回车键,按下后光标到下一行
actionGo : Go,
actionSearch : 一个放大镜
actionSend : Send
actionNext : Next
actionDone : Done,隐藏软键盘,即使不是最后一个文本输入框
- 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 效果:
EditText inputText = (EditText) findViewById(R.id. editTextId);
inputText.setImeOptions(EditorInfo.IME_ACTION_DONE);
private
final
EditText.OnEditorActionListener editorActionListener =
new
TextView.OnEditorActionListener() {
@Override
public
boolean
onEditorAction(TextView v,
int
actionId, KeyEvent event) {
if
(actionId == KeyEvent.ACTION_DOWN || actionId == EditorInfo.IME_ACTION_DONE) {
//业务代码
haoMent.createTest(Test.getId(), v.getText().toString());
UiUtils.hideSoftKeyboard(getApplicationContext(), haoTest.
this
);
v.setText(
""
);
v.clearFocus();
handler.post(updateView);
}
return
true
;
}
};
inputKey = (EditText) findViewById(R.id.contactSearch_editText);
inputKey.addTextChangedListener(watcher);
inputKey.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (KeyEvent.KEYCODE_ENTER == keyCode && event.getAction() == KeyEvent.ACTION_DOWN) {
handler.post(updateView);
return true;
}
return false;
}
});
//响应键盘内容
public TextWatcher watcher = new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i2,int i3) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
}
@Override
public void afterTextChanged(Editable editable) {
handler.post(updateView);
}
};
android:inputType=
"none"
--输入普通字符
android:inputType=
"text"
--输入普通字符
android:inputType=
"textCapCharacters"
--输入普通字符
android:inputType=
"textCapWords"
--单词首字母大小
android:inputType=
"textCapSentences"
--仅第一个字母大小
android:inputType=
"textAutoCorrect"
--前两个自动完成
android:inputType=
"textAutoComplete"
--前两个自动完成
android:inputType=
"textMultiLine"
--多行输入
android:inputType=
"textImeMultiLine"
--输入法多行(不一定支持)
android:inputType=
"textNoSuggestions"
--不提示
android:inputType=
"textUri"
--URI格式
android:inputType=
"textEmailAddress"
--电子邮件地址格式
android:inputType=
"textEmailSubject"
--邮件主题格式
android:inputType=
"textShortMessage"
--短消息格式
android:inputType=
"textLongMessage"
--长消息格式
android:inputType=
"textPersonName"
--人名格式
android:inputType=
"textPostalAddress"
--邮政格式
android:inputType=
"textPassword"
--密码格式
android:inputType=
"textVisiblePassword"
--密码可见格式
android:inputType=
"textWebEditText"
--作为网页表单的文本格式
android:inputType=
"textFilter"
--文本筛选格式
android:inputType=
"textPhonetic"
--拼音输入格式
android:inputType=
"number"
--数字格式
android:inputType=
"numberSigned"
--有符号数字格式
android:inputType=
"numberDecimal"
--可以带小数点的浮点格式
android:inputType=
"phone"
--拨号键盘
android:inputType=
"datetime"
android:inputType=
"date"
--日期键盘
android:inputType=
"time"
--时间键盘
- android软键盘的事件响应:android EditText inputType 及 android:imeOptions=”actionDone”
- android EditText inputType 及 android:imeOptions=”actionDone”
- android EditText inputType 及 android:imeOptions=”actionDone”
- 记一次,软键盘设置android:imeOptions="actionDone"在华为手机上无效的坑
- Android 软键盘事件imeOptions响应
- Android 软键盘事件imeOptions响应
- Android 软键盘事件imeOptions响应
- EditText的 android:imeOptions属性,响应事件
- android edittext inputType imeOptions 学习
- Android EditText inputType imeOptions 属性
- EditText android:imeOptions与inputType="textMultiLine" 的坑
- edittext的imeOptions属性和android软键盘的使用
- Android软键盘输入imeOptions
- Android 的 EditText inputtype
- android EditText的inputtype
- Android如何将软键盘回车换成搜索等按钮,EditText中imeOptions属性的使用
- Android 软键盘及EditText
- android 软键盘Enter键图标的设置 android:imeOptions
- 4.Redis主从复制集群搭建步骤
- [知了堂学习笔记] javascript基础练习
- FPGA串口接收代码分享
- Spring Boot 项目几种启动方式
- eclipse导入jar包
- android软键盘的事件响应:android EditText inputType 及 android:imeOptions=”actionDone”
- QT4到QT5的变化!
- linux下流媒体 ffmpeg服务器的搭建
- Ubuntu系统安装搜狗(sougou for linux)输入法安装注意事项
- 【知了堂学习笔记】_Ajax基础知识
- 2017年12月8号的工作总结
- mysql数据导出方法
- 常见算法问题
- rnn、lstm,gru中output信息说明