您的位置:首页 > 移动开发 > Android开发

Android 显示系统键盘搜索按键,实现搜索功能

2018-03-12 11:55 645 查看
系统键盘的搜索按钮,默认情况下是被隐藏的,如果要使用必须要手动设置,才可以调用搜索按键功能。
具体使用,只需要如下三个步骤:
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测试机的效果图:



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息