Android 软键盘
一、android 软件盘事件响应
如果布局中包含多个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);
添加监听事件:
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"--时间键盘

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
解决Android项目在eclipse中无法打包apk文件[bin目录下没生成apk文件]的问题
原因在于:Window-->Preferences-->Android-->Build中“Skippackaginganddexinguntilexportorlaunck”选项默认是勾上的,因此去掉该选项就OK了 解决: 1,首先把以上的那个选项去掉 2,点击Project中的Clean选项,重新编译项目 好了,现在查看bin目录应该就可以看到xx.apk文件了 本文转自 pangfc 51CTO博客,原文链接:http://blog.51cto.com/983836259/1394624,如需转载请自行联系原作者
- 下一篇
css取消a标签在移动端点击时的背景颜色(转载)
一、取消a标签在移动端点击时的蓝色 -webkit-tap-highlight-color: rgba(255, 255, 255, 0); -webkit-user-select: none; -moz-user-focus: none; -moz-user-select: none; 二、使用图片作为a标签的点击按钮时,当触发touchstart的时候,往往会有一个灰色的背景 a,a:hover,a:active,a:visited,a:link,a:focus{ -webkit-tap-highlight-color:rgba(0,0,0,0); -webkit-tap-highlight-color: transparent; outline:none; background: none; text-decoration: none; } 三、改变选中内容的背景颜色 ::selection { background: #FFF; color: #333; } ::-moz-selection { background: #FFF; color...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- Docker使用Oracle官方镜像安装(12C,18C,19C)
- Springboot2将连接池hikari替换为druid,体验最强大的数据库连接池
- Docker安装Oracle12C,快速搭建Oracle学习环境
- CentOS7安装Docker,走上虚拟化容器引擎之路
- Linux系统CentOS6、CentOS7手动修改IP地址
- CentOS6,7,8上安装Nginx,支持https2.0的开启
- CentOS7编译安装Cmake3.16.3,解决mysql等软件编译问题
- CentOS7编译安装Gcc9.2.0,解决mysql等软件编译问题
- Docker快速安装Oracle11G,搭建oracle11g学习环境
- CentOS7设置SWAP分区,小内存服务器的救世主