系统键盘上的搜索按钮默认是被隐藏的,会显示回车键,可以选择在xml给edittext添加属性,显示出来
android:imeOptions="actionSearch" android:singleLine="true" android:inputType="text" android:maxLines="1"
以上代码可以在键盘中显示搜索按钮;
imeOptions可以设置成不同参数,显示不同按键。
监听搜索键需要在代码中加入edittext监听:
etSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEARCH) { ToastUtils.showShort("开始搜索"); return true; } return false; } });