:
Default diagram:
1. Setting the EditText pattern in XML
<EditText
android:singleLine="true"
android:imeOptions="actionDone"
android:id="@+id/searchEt"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_toRightOf="@+id/icon"
android:background="@drawable/shape_white"
android:drawableLeft="@drawable/search"
android:drawablePadding="5dp"
android:gravity="left|center_vertical"
android:hint="搜索商品"
android:padding="5dp"
android:textSize="14dp" />
Special Reminder: The input box must be set to single-line mode!!!
2. Listening for input completion events in Java
searchEt.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean oneditoraction ( textview v int ActionId keyevent event ) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
//自定义的功能
doSearch();
/*隐藏软键盘*/
InputMethodManager imm = (InputMethodManager) v
.getContext().getSystemService(
Context.INPUT_METHOD_SERVICE);
if (imm.isActive()) {
imm.hideSoftInputFromWindow(
v.getApplicationWindowToken(), 0);
}
}
return false;
}
});
3. Common Confirmation Key Style description
actionNone : 回车键,按下后光标到下一行
actionGo : Go,
actionSearch : 放大镜
actionSend : Send
actionNext : Next
actionDone : Done,确定/完成,隐藏软键盘,即使不是最后一个文本输入框
From for notes (Wiz)
Android-Common code: Change the bottom right corner of the soft keyboard to determine the key style