Android设置软键盘搜索键以及监听搜索键点击时发生两次事件的问题解决
2015-07-07 11:47
639 查看
如图所示,有时候为了布局美观,在搜索时没有搜索按钮,而是调用软件盘上的按钮。调用的实现只需要在XML在输入框中加入android:imeOptions=”actionSearch”,调用软键盘时,回车键就会显示搜索二字。
然后调用 OnEditorActionListener,不是OnKeyListener
searchText.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if(actionId ==EditorInfo.IME_ACTION_SEARCH){ // 先隐藏键盘 ((InputMethodManager) searchText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE)) .hideSoftInputFromWindow( getActivity() .getCurrentFocus() .getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); //跳转activity Intent intent = new Intent(); intent.setClass(getActivity(), SearchResultActivity.class); startActivity(intent); return true; } return false; } });
在androidMainfest.xml文件中在此Activity中写入 android:windowSoftInputMode=”adjustPan”可以防止软键盘会把原来的界面挤上去的问题
相关文章推荐
- Android,TextVIew单行加省略号 ...对比较坑的问题
- 浅谈 MVP in Android
- Android应用程序签名概述
- android 出现异常重启
- 一个简短的android病毒分析
- AndroidManifest.xml文件详解
- android 导出签名APK--混淆文…
- android jni的配置
- Android - LayoutInflater
- android编译系统makefile(Android.…
- 编写自己的android jni程序
- Android 手势研究(-)
- Android手势(二)
- android4.0关于socket问题
- android4.0关于socket问题
- android string.xml中的string样式
- android 3D gallery&nbs…
- 推送androidpn基于xmpp协议
- android退出应用程序的江湖六招
- android 获得自己的IP