Android 显示系统键盘搜索按键,实现搜索功能
系统键盘的搜索按钮,默认情况下是被隐藏的,如果要使用必须要手动设置,才可以调用搜索按键功能。
具体使用,只需要如下三个步骤:
1:在布局文件中的EditText中添加如下两个属性
android:imeOptions="actionSearch" android:maxLines="1"
2:在清单文件对应的Activity中添加如下属性,防止布局被软键盘顶上去
android:windowSoftInputMode="stateAlwaysVisible|adjustPan"
3:在java代码中设置搜索按钮监听事件
给对应的EditText设置监听
serach_robot_contact_content_et.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH){//搜索按键action
SystemUtil.hideKeyboard(SearchRobotContactsActivity.this,serach_robot_contact_content_et);
content = serach_robot_contact_content_et.getText().toString();
if (TextUtils.isEmpty(content)){
return true;
}
LogUtil.d("开始搜索");
return true;
}
return false;
}
});
具体步骤完成,以下是我的小米max测试机的效果图: