Android App监听软键盘按键的三种方式与改变软键盘右下角确定键样式

actionNone : 回车键,按下后光标到下一行

actionGo : Go,

actionSearch : 放大镜

actionSend : Send

actionNext : Next

actionDone : Done,确定/完成,隐藏软键盘,即使不是最后一个文本输入框

android:singleline=”true”

android:imeoptions=”actionSearch”


EditText.setOnEditorActionListener设置监听

 @Override    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {        boolean isOK = true;        switch (actionId) { case EditorInfo.IME_ACTION_NONE: Toast.makeText(mContext, "点击-->NONE", Toast.LENGTH_SHORT).show; break; case EditorInfo.IME_ACTION_GO: Toast.makeText(mContext, "点击-->GO", Toast.LENGTH_SHORT).show; break; case EditorInfo.IME_ACTION_SEARCH: Toast.makeText(mContext, "点击-->SEARCH", Toast.LENGTH_SHORT).show; break; case EditorInfo.IME_ACTION_SEND: Toast.makeText(mContext, "点击-->SEND", Toast.LENGTH_SHORT).show; break; case EditorInfo.IME_ACTION_NEXT: Toast.makeText(mContext, "点击-->NEXT", Toast.LENGTH_SHORT).show; break; default: isOK = false; break;        }
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns_android="http://schemas.android.com/apk/res/android"    xmlns_tools="http://schemas.android.com/tools"    android_layout_width="match_parent"    android_layout_height="match_parent"    android_orientation="vertical"    android_paddingBottom="@dimen/activity_vertical_margin"    android_paddingLeft="@dimen/activity_horizontal_margin"    android_paddingRight="@dimen/activity_horizontal_margin"    android_paddingTop="@dimen/activity_vertical_margin"    tools_context="com.edwin.demokeyboard.MainActivity">    <TextView        android_layout_width="match_parent"        android_layout_height="50dp"        android_gravity="center"        android_text="改变软键盘右下角确定键样式"        android_textSize="20sp" />    <EditText        android_id="@+id/et_main_one"        android_layout_width="match_parent"        android_layout_height="wrap_content"        android_hint="actionGo"        android_imeOptions="actionGo"        android_singleLine="true" />    <EditText        android_id="@+id/et_main_two"        android_layout_width="match_parent"        android_layout_height="wrap_content"        android_hint="actionSearch"        android_imeOptions="actionSearch"        android_singleLine="true" />    <EditText        android_id="@+id/et_main_three"        android_layout_width="match_parent"        android_layout_height="wrap_content"        android_hint="actionSend"        android_imeOptions="actionSend"        android_singleLine="true" />    <EditText        android_id="@+id/et_main_four"        android_layout_width="match_parent"        android_layout_height="wrap_content"        android_hint="actionNext"        android_imeOptions="actionNext"        android_singleLine="true" /></LinearLayout>

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2016年6月16日
下一篇 2016年6月17日

相关推荐