[Android]搜索界面--自动弹出键盘,并点击键盘搜索进行搜索
来源:互联网 发布:深圳查知科技有限公司 编辑:程序博客网 时间:2024/05/16 14:16
功能分析:
进入搜索页面,自动弹出键盘,并且可以点击键盘搜索按钮进行搜索,并自动隐藏键盘。
1.在XML在输入框中加入android:imeOptions="actionSearch"
<EditText android:id="@+id/et_keyword" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_centerVertical="true" android:layout_toRightOf="@id/icon_keyword" android:background="@color/transplant" android:hint="请输入关键字" android:imeOptions="actionSearch" android:padding="5dp" android:singleLine="true" android:textColor="@color/white" android:textColorHint="@color/white" />2.自动弹出键盘
et_keyword = (EditText) findViewById(R.id.et_keyword);et_keyword.setSelected(true);et_keyword.requestFocus();//获得焦点3.然后调用 OnEditorActionListener,不是OnKeyListener(import android.widget.TextView.OnEditorActionListener;)
<span style="font-size:18px;">et_keyword.setOnEditorActionListener(new OnEditorActionListener() {@Overridepublic boolean onEditorAction(TextView arg0, int arg1, KeyEvent arg2) {if (arg1 == EditorInfo.IME_ACTION_SEARCH) { //添加搜索事件 hideInput(mContext);//隐藏软键盘 }return false;}});</span>
/** * 隐藏软键盘 */ private static InputMethodManager manager;// 输入法管理器 用户隐藏软键盘private void hideInput(Context context) {if(manager==null){manager = ((InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE));}manager.hideSoftInputFromWindow(((Activity) context).getCurrentFocus().getWindowToken(),InputMethodManager.HIDE_NOT_ALWAYS);}
3.在androidMainfest.xml文件中在此Activity中写入 android:windowSoftInputMode="adjustPan"可以防止软键盘会把原来的界面挤上去的问题,stateVisible负责让键盘自动弹出
<span style="font-size:18px;">android:windowSoftInputMode="adjustPan|stateVisible"</span>
0 1
- [Android]搜索界面--自动弹出键盘,并点击键盘搜索进行搜索
- Android搜索框输入内容点击键盘的搜索按钮进行搜索
- 如何弹出搜索类型键盘
- 将editText弹出的键盘变成搜索
- input弹出的手机键盘搜索事件
- visual studio 搜索技巧——通过键盘进行搜索
- 移动端input弹出带有搜索按钮的键盘与获取点击搜索按钮触发的事件
- 移动端input弹出带有搜索按钮的键盘与获取点击搜索按钮触发的事件
- 2、移动端input弹出带有搜索按钮的键盘与获取点击搜索按钮触发的事件
- 键盘变搜索按钮
- appium 键盘搜索
- 手机端键盘搜索
- Android EditView 设置键盘搜索,回车
- android 监听键盘事件,搜索,确定
- Android EditText 设置键盘 搜索,回车
- Android EditText 设置键盘 搜索,回车
- Android EditText 设置键盘 搜索,回车
- Android enter键设置键盘搜索回车
- CString.Format的详细用法(转)
- VS2013自带的Newtonsoft导致的编译异常
- 线段树基础
- Source Insight用法
- ubuntu下android开发安装手机驱动
- [Android]搜索界面--自动弹出键盘,并点击键盘搜索进行搜索
- Android 中的setTag()/getTag()
- 如何让Eclipse同时导入2个相同的项目
- [SC-04]代码优化
- 【云存储】企业云存储管理解决方案
- C/C++中for()循环中的判断语句
- 从TS流到PAT和PMT
- CentOS服务器下JavaEE环境搭建指南(远程桌面+JDK+Tomcat+MySQL)
- Android 4.4 WebView实现分析