android:imeOptions属性
发布日期:2021-06-29 15:21:48
浏览次数:3
分类:技术文章
本文共 3338 字,大约阅读时间需要 11 分钟。
---------------------
默认情况下软键盘右下角的按钮为“下一个”,点击会到下一个输入框,保持软键盘
设置 android:imeOptions="actionDone" ,软键盘下方变成“完成”,点击后光标保持在原来的输入框上,并且软键盘关闭 android:imeOptions="actionSend" 软键盘下方变成“发送”,点击后光标移动下一个 在这里设置的imeOptions如何使用呢?如下面的代码,让EditText实现setOnEditorActionListener,在onEditAction方法中actionId就对应我们设置的imeOptions。系统默认的actionId有:EditorInfo.IME_NULL、EditorInfo.IME_ACTION_SEND、EditorInfo.IME_ACTION_DONE等。这样我们就可以根据不同的EditText来实现不同的软键盘右下角功能键。 Java代码 package com.test; import com.test.main.TestAsyn; import android.app.Activity; import android.os.Bundle; import android.view.KeyEvent; import android.view.inputmethod.EditorInfo; import android.widget.EditText; import android.widget.TextView; import android.widget.TextView.OnEditorActionListener; import android.widget.Toast; public class IMFActivity extends Activity implements OnEditorActionListener { EditText etDefault; EditText etEmail; EditText etNumber; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.imf_layout); etDefault = (EditText)findViewById(R.id.default_content); etEmail = (EditText)findViewById(R.id.email_content); etNumber = (EditText)findViewById(R.id.number_content); etDefault.setOnEditorActionListener(this); etEmail.setOnEditorActionListener(this); etNumber.setOnEditorActionListener(this); } @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { switch(actionId){ case EditorInfo.IME_NULL: System.out.println("null for default_content: " + v.getText() ); break; case EditorInfo.IME_ACTION_SEND: System.out.println("action send for email_content: " + v.getText()); break; case EditorInfo.IME_ACTION_DONE: System.out.println("action done for number_content: " + v.getText()); break; } //Toast.makeText(this, v.getText()+"--" + actionId, Toast.LENGTH_LONG).show(); return true; } } xml文件: Xml代码 <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TableLayout android:layout_width="fill_parent" android:layout_height="fill_parent"> <TableRow> <TextView android:text="No special rules" android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView> <EditText android:text="1111111111111" android:id="@+id/default_content" android:layout_width="fill_parent" android:layout_height="wrap_content"></EditText> </TableRow> <TableRow> <TextView android:text="Email address:" android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView> <EditText android:text="" android:id="@+id/email_content" android:layout_width="fill_parent" android:layout_height="wrap_content" android:inputType="text|textEmailAddress" android:imeOptions="actionSend"></EditText> </TableRow> <TableRow> <TextView android:text="Signed decimal number:" android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView> <EditText android:text="" android:id="@+id/number_content" android:layout_width="fill_parent" android:layout_height="wrap_content" android:inputType="number|numberSigned|numberDecimal" android:imeOptions="actionDone"></EditText> </TableRow> </TableLayout> </ScrollView>转载地址:https://codegg.blog.csdn.net/article/details/19679929 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
逛到本站,mark一下
[***.202.152.39]2024年04月04日 20时02分32秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
Random SecureRandom 随机数生成阻塞问题
2019-04-29
tomcat8.5.15 apr模式运行 配置
2019-04-29
Linux命令笔记
2019-04-29
ElasticSearch5.4.3 环境搭建 2017 (1-单节点模式/开发模式)
2019-04-29
ElasticSearch5.4.3 环境搭建 2017 (2-集群搭建)
2019-04-29
Mysql 使用全文索引
2019-04-29
ElasticSearch5.4.3 环境搭建 2017 (6-IK中文分词插件)
2019-04-29
MongoDB基本操作
2019-04-29
Ionic 入门与实战之第二章第二节:Ionic 环境搭建之 Ionic Lab 使用
2019-04-29
Ionic 入门与实战之第二章第一节:Ionic 环境搭建之开发环境配置
2019-04-29
Ionic 入门与实战之第三章:Ionic 项目结构以及路由配置
2019-04-29
Ionic 2.0 相关资料
2019-04-29