// 设置该SearchView默认是否自动缩小为图标
mSearchView.setIconifiedByDefault(false);
// 为该SearchView组件设置事件监听器
mSearchView.setOnQueryTextListener(this);
// 设置该SearchView显示确认搜索按钮
mSearchView.setSubmitButtonEnabled(true);
// 设置该SearchView内默认显示的提示文本
mSearchView.setQueryHint("查找");

//设置

mSearchView.setIconified(false);

//清除焦点

mSearchView.clearFocus();

//获取焦点

mSearchView.requestFocus();



EditText默认自动获取焦点的,会弹出软键盘

下面是关闭SearchView自动获取焦点的代码

<span style="font-size:14px;"><span style="font-size:14px;"> <LinearLayout
android:id="@+id/focus"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:background="#EAEAEA"
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="center_vertical"
android:orientation="horizontal" > <SearchView
android:id="@+id/searchView"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_marginRight="20dp"
android:gravity="left|center_vertical"
android:iconifiedByDefault="false"
android:inputType="textFilter"
android:queryHint="输入IP"
android:textColor="#ABABAB"
android:textColorHint="#ABABAB" /> </LinearLayout></span></span>

只需要在SearchView的父级控件中添加以下属性:

<span style="font-size:14px;"><span style="font-size:14px;">android:focusable="true"
android:focusableInTouchMode="true"</span></span>

就在进入的时候不会自动获取焦点

但是当你点击SearchView获取焦点后,到别的activity再回来的时候,失效了,总是自动获取焦点并且弹出软键盘。

这里有个办法就是在onResume方法里添加以下代码

<span style="font-size:14px;"><span style="font-size:14px;">@Override
protected void onResume() {
super.onResume();
mSearchView.setFocusable(true);
mSearchView.setFocusableInTouchMode(true);
//mSearchView.requestFocus(); //获取焦点
}</span></span>

回到这个activity会执行onResume方法,让它执行上面的代码,就不再会自动获取焦点了。

最新文章

  1. nopcommerce之一(结构分析)
  2. jquery工具方法makeArray/merge
  3. 数据库中 dbo是什么意思
  4. PHP访问REST API上传文件的解决方案
  5. Python 异常结构
  6. GridView下DropDownList 的选择方法onselectedindexchanged 实现方法
  7. 转载 Eclipse下的SSH开发例子
  8. Java IO 和 NIO
  9. TCP四次挥手
  10. swift3.0 基础练习-实现99乘法表
  11. Python爬虫实例:爬取豆瓣Top250
  12. Apache Flink系列(1)-概述
  13. 判断浏览器大于等于ie9
  14. jQuery中删除方法empty(),remove()和detach()的区别
  15. JMeter实现登录初始化(类似LR的init函数功能实现)
  16. Python 第五阶段 学习记录之---Django 基础
  17. WorkerMan 入门学习之(三)基础教程-Timer类的使用
  18. 随笔:JS对象无new构造原理
  19. CSS的再深入2(更新中&#183;&#183;&#183;)
  20. 前端-CSS-2-选择器

热门文章

  1. 2018java开发一些面经
  2. 【Android 应用开发】Ubuntu 下 Android Studio 开发工具使用详解
  3. BluetoothDevice详解
  4. Python基础1 Hello World!
  5. 【转载】Windows下Mysql5.7开启binlog步骤及注意事项
  6. ubuntu 安装lua错误
  7. PHPcmsv9 还原数据库 操作步骤
  8. netbeans调试配置
  9. tcp传送报文
  10. Maven 生命周期 和插件