默认情况下软键盘右下角的按钮为“下一个”,点击会到下一个输入框,保持软键盘

设置 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来实现不同的软键盘右下角功能键。
 
  1. package com.test;
  2. import com.test.main.TestAsyn;
  3. import android.app.Activity;
  4. import android.os.Bundle;
  5. import android.view.KeyEvent;
  6. import android.view.inputmethod.EditorInfo;
  7. import android.widget.EditText;
  8. import android.widget.TextView;
  9. import android.widget.TextView.OnEditorActionListener;
  10. import android.widget.Toast;
  11. public class IMFActivity extends Activity implements OnEditorActionListener {
  12. EditText etDefault;
  13. EditText etEmail;
  14. EditText etNumber;
  15. /** Called when the activity is first created. */
  16. @Override
  17. public void onCreate(Bundle savedInstanceState) {
  18. super.onCreate(savedInstanceState);
  19. setContentView(R.layout.imf_layout);
  20. etDefault = (EditText)findViewById(R.id.default_content);
  21. etEmail = (EditText)findViewById(R.id.email_content);
  22. etNumber = (EditText)findViewById(R.id.number_content);
  23. etDefault.setOnEditorActionListener(this);
  24. etEmail.setOnEditorActionListener(this);
  25. etNumber.setOnEditorActionListener(this);
  26. }
  27. @Override
  28. public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
  29. switch(actionId){
  30. case EditorInfo.IME_NULL:
  31. System.out.println("null for default_content: " + v.getText() );
  32. break;
  33. case EditorInfo.IME_ACTION_SEND:
  34. System.out.println("action send for email_content: "  + v.getText());
  35. break;
  36. case EditorInfo.IME_ACTION_DONE:
  37. System.out.println("action done for number_content: "  + v.getText());
  38. break;
  39. }
  40. //Toast.makeText(this, v.getText()+"--" + actionId, Toast.LENGTH_LONG).show();
  41. return true;
  42. }
  43. }
 
xml文件:
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    3. android:layout_width="fill_parent" android:layout_height="fill_parent">
    4. <TableLayout android:layout_width="fill_parent"
    5. android:layout_height="fill_parent">
    6. <TableRow>
    7. <TextView android:text="No special rules" android:id="@+id/TextView01"
    8. android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
    9. <EditText android:text="1111111111111" android:id="@+id/default_content"
    10. android:layout_width="fill_parent" android:layout_height="wrap_content"></EditText>
    11. </TableRow>
    12. <TableRow>
    13. <TextView android:text="Email address:" android:id="@+id/TextView01"
    14. android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
    15. <EditText android:text="" android:id="@+id/email_content"
    16. android:layout_width="fill_parent" android:layout_height="wrap_content"
    17. android:inputType="text|textEmailAddress"
    18. android:imeOptions="actionSend"></EditText>
    19. </TableRow>
    20. <TableRow>
    21. <TextView android:text="Signed decimal number:" android:id="@+id/TextView01"
    22. android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
    23. <EditText android:text="" android:id="@+id/number_content"
    24. android:layout_width="fill_parent" android:layout_height="wrap_content"
    25. android:inputType="number|numberSigned|numberDecimal"
    26. android:imeOptions="actionDone"></EditText>
    27. </TableRow>
    28. </TableLayout>
    29. </ScrollView>

imeOptions 属性详解的更多相关文章

  1. Android TextView和EditText属性详解

    TextView属性详解: autoLink设置 是否当文本为URL链接/email/电话号码/map时,文本显示为可点击的链接.可选值(none/web /email/phone/map/all) ...

  2. EditText属性详解

    关于EditText属性详解很详细的记录,转过来收着 1.EditText输入的文字为密码形式的设置 (1)通过.xml里设置: 把该EditText设为:android:password=" ...

  3. Android textAppearance的属性设置及TextView属性详解

    textAppearance的属性设置 android:textAppearance="?android:attr/textAppearanceSmall" android:tex ...

  4. Android笔记-2-TextView的属性详解

    [Android 基础]TextView的属性详解 android:autoLink :设置是否当文本为URL链接/email/电话号码/map时,文本显示为可点击的链接.可选值(none/web / ...

  5. android:exported 属性详解

    属性详解 标签: android 2015-06-11 17:47 27940人阅读 评论(7) 收藏 举报 分类: Android(95) 项目点滴(25) 昨天在用360扫描应用漏洞时,扫描结果, ...

  6. OutputCache属性详解(一)一Duration、VaryByParam

    目录 OutputCache概念学习 OutputCache属性详解(一) OutputCache属性详解(二) OutputCache属性详解(三) OutputCache属性详解(四)— SqlD ...

  7. OutputCache属性详解(二)一 Location

    目录 OutputCache概念学习 OutputCache属性详解(一) OutputCache属性详解(二) OutputCache属性详解(三) OutputCache属性详解(四)— SqlD ...

  8. OutputCache属性详解(三)— VaryByHeader,VaryByCustom

    目录 OutputCache概念学习 OutputCache属性详解(一) OutputCache属性详解(二) OutputCache属性详解(三) OutputCache属性详解(四)— SqlD ...

  9. OutputCache属性详解(四)— SqlDependency

    目录 OutputCache概念学习 OutputCache属性详解(一) OutputCache属性详解(二) OutputCache属性详解(三) OutputCache属性详解(四)— SqlD ...

随机推荐

  1. 微软DbHelper

    using System; using System.Configuration; using System.Data; using System.Data.Common; using System. ...

  2. .Net用户控件

    用户控件用户控件是个什么东西?自定义的反复重用的控件集合 好处?1.代码重用2.结构良好3.分工开发4.局部缓存 难点:一.交换信息: 注意信息的交换只在相邻层之间进行交换,如果是嵌套交换信息除Ses ...

  3. FZU 2143 Board Game

    Board Game Accept: 95    Submit: 246Time Limit: 1000 mSec    Memory Limit : 32768 KB  Problem Descri ...

  4. 卡尔曼滤波—Simple Kalman Filter for 2D tracking with OpenCV

    之前有关卡尔曼滤波的例子都比较简单,只能用于简单的理解卡尔曼滤波的基本步骤.现在让我们来看看卡尔曼滤波在实际中到底能做些什么吧.这里有一个使用卡尔曼滤波在窗口内跟踪鼠标移动的例子,原作者主页:http ...

  5. git log 查看 提交历史

    在提交了若干更新之后,又或者克隆了某个项目,想回顾下提交历史,可以使用 Git log 命令查看. 接下来的例子会用我专门用于演示的 simplegit 项目,运行下面的命令获取该项目源代码: git ...

  6. IP地址验证

    /** * 验证IP地址 * * @param 待验证的字符串 * @return 如果是符合格式的字符串,返回 <b>true </b>,否则为 <b>false ...

  7. JAVA排序--[插入排序]

    package com.array; public class Sort_Insert { /* * 项目名称:插入排序 ; * 项目要求:用JAVA对数组进行排序,并运用插入排序算法; * 作者:S ...

  8. linux包的相关命令

    apt-cache search package 搜索包 apt-cache show package 获取包的相关信息,如说明.大小.版本等 sudo apt-get install package ...

  9. sar 找出系统瓶颈的利器

    sar 找出系统瓶颈的利器sar是System Activity Reporter(系统活动情况报告)的缩写.sar工具将对系统当前的状态进行取样,然后通过计算数据和比例来表达系统的当前运行状态.它的 ...

  10. GATK3.2.2小结(转载)

    http://blog.csdn.net/skenoy/article/details/38346489 经过几天的摸索和网上资料的查询对GATK软件有点小心得,现总结如下: 1. fasta文件最好 ...