将软键盘的回车按钮变为搜索按钮
来源:互联网 发布:淘宝银行卡怎么解绑 编辑:程序博客网 时间:2024/05/16 14:34
网上有很多案例,我就直接转了
但是有一个问题,就是进行按钮监听的时候会出发两次搜索事件
于是乎,又进行度娘得到了答案
然后调用 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"可以防止软键盘会把原来的界面挤上去的问题
但是有一个问题,就是进行按钮监听的时候会出发两次搜索事件
于是乎,又进行度娘得到了答案
然后调用 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"可以防止软键盘会把原来的界面挤上去的问题
0 0
- 将软键盘的回车按钮变为搜索按钮
- 将软键盘的回车按钮变为搜索按钮
- Android 将软键盘的回车按钮改变成搜索按钮
- Android如何将软键盘回车换成搜索等按钮,EditText中imeOptions属性的使用
- android设置软键盘的回车按钮为搜索键
- EditText软键盘的回车按钮,改状态。
- Android 将软键盘Enter变为搜索
- Android edittext将软键盘的回车改为搜索
- EditText点击的时候软键盘上出现搜索按钮
- EditText点击的时候软键盘上出现搜索按钮
- EditText弹出的软键盘带搜索按钮
- 让手机软键盘出现“搜索”按钮
- 软键盘搜索按钮绑定使用
- 手机软键盘搜索按钮实现点击搜索功能
- 点击按钮自动添加行 + 点击按钮,将行变为可输入的文本框
- android在点击搜索按钮同时关闭软键盘
- EditText在手机弹出的软键盘中,将回车键变为搜索键和点击搜索键时,执行2次搜索解决
- Android软键盘回车键变为搜索键
- Android应用程序互保方案
- android异步加载之Handler、AsyncTask(一)
- Android studio正确配置AndroidAnnotation注解
- leetcode-326-Power of Three
- ASP.NET第一部分总结
- 将软键盘的回车按钮变为搜索按钮
- 作为一场新的挑战。
- Java JSON库Jackson 2.x新变化一览
- jQuery 核心
- CocoaPods的下载和安装及常见问题
- Camera Function - 摄像头功能说明
- CentOS(Linux)下如何安装源码包
- 基于 zepto 的触摸函数封装
- cocos2dx 音频模块分析(2): 音效部分