admin管理员组文章数量:1562435
首先在布局文件中添加下面这两行
然后在java代码中添加输入框的监听
//设置输入框监听
film_ed_search.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
//注意:搜狗输入法需要多加后面一层判断EditorInfo.IME_ACTION_UNSPECIFIED
if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_UNSPECIFIED) {//搜索按键
((InputMethodManager) film_ed_search.getContext()
.getSystemService(Context.INPUT_METHOD_SERVICE))
.hideSoftInputFromWindow(getActivity().getCurrentFocus()
.getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
//实现自己的搜索逻辑
String searchKey = film_ed_search.getText().toString().trim();
if (TextUtils.isEmpty(searchKey)) {
showToast("输入内容不能为空哦");
return false;
}
//跳转
Intent intent = new Intent(getActivity(), SearchCinemaActivity.class);
intent.putExtra("searchCinema", film_ed_search.getText().toString());
startActivity(intent);
return true;
}
return false;
}
});
效果如下
版权声明:本文标题:输入法换行按钮变搜索 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dongtai/1727479349a1116628.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论