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>
源碼地址: