Android EditText 软键盘搜索事件
2015-06-10 17:13
351 查看
只需要在XML在输入框中加入android:imeOptions=”actionSearch”,调用软键盘时,回车键就会显示搜索二字。
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);
});
在androidMainfest.xml文件中在此Activity中写入 android:windowSoftInputMode=”adjustPan”可以防止软键盘会把原来的界面挤上去的问题
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 shape的使用
- Android缓存Cache学习
- android模拟器滑动界面时,自动输出'C'的问题
- 扫描二维码自动识别手机系统(Android/IOS)
- Android中级教程(三)之不同Activity之间的数据传递---Bundle对象的使用!
- [android]Xutils详细介绍
- Android中级教程(二)之调用另一个Activity---Intent对象的使用!
- 为什么Android的图片质量会比iPhone的差?
- Android 属性动画(Property Animation) 完全解析 (下)
- Android应用的自动升级、更新模块的实现
- Android的事件处理-android学习之旅(四十四)
- Android的事件处理-android学习之旅(四十四)
- Android的事件处理-android学习之旅(四十四)
- Android strings.xml中空格符的标识步骤附xml特殊字符表示法
- Android基础教程之-------Android中两种设置全屏的方法!!!
- android数据存储读取5:Sqlite一些要注意的地方
- Android5.1--APK包的安装、卸载和优化(PackageManagerService)(一)
- 【Android】解决RadioButton+FragmentPagerAdapter+Fragment切换页面数据加载的问题
- Android基础教程(七)之----单选项框RadioGroup的综合应用
- android.os.NetworkOnMainThreadException异常原因