您的位置:首页 > 移动开发 > Android开发

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);

return true;
}
return false;
}


});

在androidMainfest.xml文件中在此Activity中写入 android:windowSoftInputMode=”adjustPan”可以防止软键盘会把原来的界面挤上去的问题
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: