在android的实践开发中,为了界面的美观,往往那些搜索框并没有带搜索按钮,而是调用了软键盘的搜索按钮,完成这次时间
  • 1
  • 2


好吧!直接上代码!

<EditText
android:id="@+id/my_chat_seach"
android:layout_width="fill_parent"
android:layout_height="23dp"
android:layout_centerVertical="true"
android:layout_marginRight="6dip"
android:layout_toRightOf="@id/my_seach_item_1_button"
android:background="@color/white"
android:gravity="center_vertical"
android:hint="@string/search"
android:imeOptions="actionSearch"
android:singleLine="true"
android:textColor="#8e8787"
android:textSize="13sp" />

xml配置文件中 最重要的一个属性是: android:imeOptions=”actionSearch”,从而调用软键盘时,回车键就会显示搜索二字。
同时在androidMainfest.xml文件中在此Activity中写入 android:windowSoftInputMode=”adjustPan”,可以防止软键盘会把原来的界面挤上去的问题。
那么在该activity中,如何操作呢?

seachEditText = (EditText) findViewById(R.id.my_chat_seach);
watchSearch();

然后

/**
* @方法说明:监控软键盘的的搜索按钮
* @方法名称:watchSearch
* @返回值:void
*/
public void watchSearch() {
seachEditText.setOnEditorActionListener(new OnEditorActionListener() { @Override
public boolean onEditorAction(TextView v, int actionId,
KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
// 先隐藏键盘
((InputMethodManager) seachEditText.getContext()
.getSystemService(Context.INPUT_METHOD_SERVICE))
.hideSoftInputFromWindow(ChatFriendsGroudSeach.this
.getCurrentFocus().getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
// 搜索,进行自己要的操作...
seachList(viewIndex);//这里是我要做的操作!
return true;
}
return false;
}
});
}

好的!完成!

android 监控软键盘确定 搜索 按钮并赋予点击事件的更多相关文章

  1. Android隐藏软键盘收回软键盘

    代码改变世界 Android隐藏软键盘收回软键盘 InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPU ...

  2. 开发移动端web应用, 使用手机自带键盘的搜索按钮

    很多时候在移动端的web页面中, 需要使用搜索功能, 然而页面中并没有太多的空间来放置一个像pc端上那样的搜索按钮, 这时候就需要借用手机输入法自带的搜索按钮来实现点击搜索 虽然不是什么大的功能, 但 ...

  3. Android中软键盘展示、EditText焦点获取及windowSoftInputMode属性探究

    2017-08-14 21:44:23 有很多中情况,分别展示. 1.Activity不做任何设置,布局使用LinearLayout 会自动滚动EditText之上的所有View,代码: <?x ...

  4. (转载) EditText初始不弹出软键盘,只有光标显示,点击再弹出

    EditText初始不弹出软键盘,只有光标显示,点击再弹出 2013-06-08 10:13 21305人阅读 评论(5) 收藏 举报  分类: android基础(91)  版权声明:本文为博主原创 ...

  5. android设置软键盘搜索键以及监听搜索键点击时发生两次事件的问题解决

    在输入框中加入android:imeOptions="actionSearch",调用软键盘时,回车键就会显示搜索二字. 我想在点击搜索时,跳转到下一个页面,但是调用setOnKe ...

  6. Android 设置软键盘搜索键以及监听搜索键点击事件

    如图所示,有时候为了布局美观,在搜索时没有搜索按钮,而是调用软件盘上的按钮.调用的实现只需要在XML在输入框中加入android:imeOptions="actionSearch" ...

  7. 自定义View 实现软键盘实现搜索

    1. xml文件中加入自定义 搜索view <com.etoury.etoury.ui.view.IconCenterEditText android:id="@+id/search_ ...

  8. Android控制软键盘的弹出和隐藏

    弹出软键盘 前提:必须要有一个可以编辑的控件(EditText),并且当前已经获取焦点 /** * 弹出软键盘 */ public void openKeyboard(View view) { // ...

  9. Android手动控制软键盘的开启和关闭,判断软键盘是否显示;

    工具类,拿走就能用: import android.annotation.TargetApi; import android.app.Activity; import android.content. ...

随机推荐

  1. php中mvc新建页面

    PHP配置: <?phpclass appointmentController extends Controller{public function __construct(){parent:: ...

  2. ZOJ-2753

    Min Cut (Destroy Trade Net) Time Limit: 15 Seconds      Memory Limit: 32768 KB Given an undirected g ...

  3. Disruptor Ringbuffer

    系列译文: http://ifeve.com/disruptor/ 当有多个消费者时,(按Disruptor的设计)每个消费者各自控制自己的指针,依次读取每个Slot(也就是每个消费者都会读取到所有的 ...

  4. Linux下服务器搭建

    一.安装前准备工作 yum -y install gcc   yum -y install gcc-c++   yum -y install make yum -y install ncurses-d ...

  5. echarts官网上的动态加载数据bug被我解决。咳咳/。

    又是昨天,为什么昨天发生了这么多事.没办法,谁让我今天没事可做呢. 昨天需求是动态加载数据,画一个实时监控的折线图.大概长这样. 我屁颠屁颠的把代码copy过来,一运行,caocaocao~bug出现 ...

  6. 转:Awesome Vulnerability Research

    转:https://github.com/re-pronin/Awesome-Vulnerability-Research Awesome Vulnerability Research 

  7. 【转载】AsyncTask源码分析

    原文地址:https://github.com/white37/AndroidSdkSourceAnalysis/blob/master/article/AsyncTask%E5%92%8CAsync ...

  8. AndroidManifest.xml文件详解(application)

    http://blog.csdn.net/think_soft/article/details/7557101 语法(SYNATX): <application android:allowTas ...

  9. python实现RabbitMQ同步跟异步消费模型

    1,消息推送类 import pika # 同步消息推送类 class RabbitPublisher(object): # 传入RabbitMQ的ip,用户名,密码,实例化一个管道 def __in ...

  10. Spring Boot高级

    Spring Boot高级内容概要一.Spring Boot与缓存二.Spring Boot与消息三.Spring Boot与检索四.Spring Boot与任务五.Spring Boot与安全六.S ...