EditText中imeOptions属性使用及设置无效解决
2015-12-25 11:16
671 查看
虽然通常输入法软键盘右下角会是回车按键。
但我们经常会看到点击不同的编辑框,输入法软键盘右下角会有不同的图标。
点击浏览器网址栏的时候,输入法软键盘右下角会变成“GO”或“前往”。
而我们点击Google搜索框,输入法软键盘右下角会变成 “放大镜” 或者 “搜索”。
而决定这个图标的变换的参数就是EditText中的 android:imeOptions。
android:imeOptions的值有actionGo、 actionSend 、actionSearch、actionDone等,这些意思都很明显。
[html]
view plaincopy
<EditText
android:id="@+id/editText"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:imeOptions="actionSearch"
/>
而其在Java代码中对应的值为EditorInfo.IME_ACTION_XXX 。
在代码中通过editText.setOnEditorActionListener方法添加相应的监听,因为有些action是需要在代码中添加具体的相关操作的。
[java]
view plaincopy
EditText editText = (EditText) contentView.findViewById(R.id.editText);
editText.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId,
KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
Toast.makeText(getActivity(), "1111111",Toast.LENGTH_SHORT).show();
}
return false;
}
});
然而当我们设置这一切后,却发现点击输入框,输入法键盘完全没变化,还是回车键。
这并不是上面的属性和方法无效,而是我们还需要设置别的属性来使它们生效。
经过试验,设置下面两个属性中的一个即可使这个属性生效。(应该还有其他的属性也可以,没去试验。)
1 将singleLine设置为true。
2 将inputType设置为text 。
[html]
view plaincopy
<EditText
android:id="@+id/editText"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:imeOptions="actionSearch"
android:singleLine="true"
android:inputType="text"
/>
java代码设置
[java]
view plaincopy
editText.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
editText.setInputType(EditorInfo.TYPE_CLASS_TEXT);
editText.setSingleLine(true);
但我们经常会看到点击不同的编辑框,输入法软键盘右下角会有不同的图标。
点击浏览器网址栏的时候,输入法软键盘右下角会变成“GO”或“前往”。
而我们点击Google搜索框,输入法软键盘右下角会变成 “放大镜” 或者 “搜索”。
而决定这个图标的变换的参数就是EditText中的 android:imeOptions。
android:imeOptions的值有actionGo、 actionSend 、actionSearch、actionDone等,这些意思都很明显。
[html]
view plaincopy
<EditText
android:id="@+id/editText"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:imeOptions="actionSearch"
/>
而其在Java代码中对应的值为EditorInfo.IME_ACTION_XXX 。
在代码中通过editText.setOnEditorActionListener方法添加相应的监听,因为有些action是需要在代码中添加具体的相关操作的。
[java]
view plaincopy
EditText editText = (EditText) contentView.findViewById(R.id.editText);
editText.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId,
KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
Toast.makeText(getActivity(), "1111111",Toast.LENGTH_SHORT).show();
}
return false;
}
});
然而当我们设置这一切后,却发现点击输入框,输入法键盘完全没变化,还是回车键。
这并不是上面的属性和方法无效,而是我们还需要设置别的属性来使它们生效。
经过试验,设置下面两个属性中的一个即可使这个属性生效。(应该还有其他的属性也可以,没去试验。)
1 将singleLine设置为true。
2 将inputType设置为text 。
[html]
view plaincopy
<EditText
android:id="@+id/editText"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:imeOptions="actionSearch"
android:singleLine="true"
android:inputType="text"
/>
java代码设置
[java]
view plaincopy
editText.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
editText.setInputType(EditorInfo.TYPE_CLASS_TEXT);
editText.setSingleLine(true);
相关文章推荐
- windows下Nginx+Tomcat
- Hadoop2.4.1学习笔记(一)之ssh远程登录原理
- 使用Compose变量定制Docker网络
- Apache Camel TypeConverter的使用
- open()参数宏的意义
- linux 用户管理
- linux 常用命令
- linux进程管理与调度
- Linux常见命令汇总
- linux 文件名命名规则
- opencv中与split()与merge()的问题
- 架构
- 菜鸟学Linux命令:端口查看和操作命令
- linux上tomcat的安装配置(多个tomcat)
- Linux内核高性能优化【生产环境实例】
- nginx配置 防ddos
- 架构
- 编译安装lamp环境
- Nginx 基础架构
- 各大网站CSS代码初始化集合