项目当中 有关键词搜索商品,但是 又不想单独做一个按钮 那么就更改一下软键盘的enter键 来帮助实现这个需求

 一些注意事项 全部写在 注释当中这里不在赘述

 

xml代码

    android:textColorHint="#CCCCCC"    android:background="@drawable/drouble"    android:id="@+id/search"    android:hint="搜索需要的商品..."    android:textSize="13dip"    android:layout_width="12dp"    android:layout_weight="4"    android:layout_height="match_parent"    android:imeOptions="actionSearch"    android:inputType="text"    android:singleLine="true"     />
/*****/
    android:imeOptions="actionSearch"    android:inputType="text"    android:singleLine="true"   这三条属性必须加上

java代码


//        http://my.oschina.net/u/2444750/blog/523209 更改软件盘 Enter键 属性        editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {            @Override            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {                if (actionId == EditorInfo.IME_ACTION_DONE) {                    Toast.makeText(getApplicationContext(), "换行键已更改", Toast.LENGTH_SHORT).show();                    ((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(                            MainActivity.this.getCurrentFocus().getWindowToken(),                            InputMethodManager.HIDE_NOT_ALWAYS);                }                return false;            }        });//点击软键盘搜索按钮后隐藏掉软键盘        final InputMethodManager manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);        editText.setOnKeyListener(new View.OnKeyListener() {            @Override            public boolean onKey(View v, int keyCode, KeyEvent event) {                if (event.getAction() == MotionEvent.ACTION_DOWN) {                    if (getCurrentFocus() != null && getCurrentFocus().getWindowToken() != null) {                        manager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);                    }                }                return false;            }        });//        .actionUnspecified 未指定,对应常量EditorInfo.IME_ACTION_UNSPECIFIED.//        2.actionNone 没有动作,对应常量EditorInfo.IME_ACTION_NONE//        3.actionGo 去往,对应常量EditorInfo.IME_ACTION_GO//        4.actionSearch 搜索,对应常量EditorInfo.IME_ACTION_SEARCH//        5.actionSend 发送,对应常量EditorInfo.IME_ACTION_SEND//        6.actionNext 下一个,对应常量EditorInfo.IME_ACTION_NEXT//        7.actionDone 完成,对应常量EditorInfo.IME_ACTION_DONE

更多相关文章

  1. android快速上手(二)android开发环境搭建及hello world
  2. (Android)react-native更改状态栏文字和图标颜色
  3. android:onClick都做了什么
  4. [Android(安卓)Studio / NDK] 如何使用javah生成.h文件
  5. android 属性android:visibility及 view的setVisibility方法值的
  6. Android(安卓)ListView元素间隙线自定义渐变效果
  7. android webkit CSS3及Render初窥
  8. Android(安卓)Input子系统-含实例源码
  9. Android开源项目解析:PullToRefresh

随机推荐

  1. 缓存函数的简单使用
  2. Windows还原系统后分区合并为一个分区恢
  3. php简单的数组递归
  4. 通过链式调用,将一个类委托给另一个类实现
  5. 今天记录下极光推送
  6. 几种常用设计模式的简单示例
  7. 命名空间自动加载进阶与mysql初体验
  8. phpquery中文手册
  9. php递归将数组拼接为url
  10. 0820作业