布局:

这是我项目里的布局文件,想要让EditText 显示搜索,最主要是两个配置:

android:imeOptions="actionSearch"android:singleLine="true"

点击搜索框隐藏键盘:

search_input.setOnEditorActionListener(new TextView.OnEditorActionListener() {            @Override            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {                if (actionId == EditorInfo.IME_ACTION_SEARCH) {                    // 当按了搜索之后关闭软键盘                    Utils.hideKeyboard(search_input);                    return true;                }                return false;            }        });
这里用到的工具类
 Utils.hideKeyboard(search_input);

如下:

/** * 隐藏软键盘 * * @param context :上下文环境,一般为Activity实例 * @param view    :一般为EditText */public static void hideKeyboard(View view) {InputMethodManager manager = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);manager.hideSoftInputFromWindow(view.getWindowToken(), 0);}
轻松实现搜素,并且点击隐藏键盘。

更多相关文章

  1. 相对布局RelativeLayout
  2. android布局ui
  3. 虚拟键盘弹出时挡住EditText的解决方案
  4. Android TextView布局__2019.09.02
  5. Android软键盘弹出,界面整体上移的问题
  6. Android使用Shape实现布局圆角边框

随机推荐

  1. 如何在Android单元测试中调试async-http
  2. Android(安卓)Studio电脑不支持HAXM的解
  3. Android获取移动设备的IP地址
  4. Android(安卓)修改系统时间代码
  5. Android之TabHost的几种使用方法
  6. Android(安卓)RecyclerView的简单使用
  7. android手机短信总结
  8. Android几个常用功能代码(校园助手开发笔
  9. android MVVM ItemViewSelector 实现列表
  10. android计算器