最近在做一个项目,当我点击跳转至一个带有EditText的界面后,模拟器中的软键盘会自动弹出,严重影响了用户体验。在网上找了资料,现总结如下。

我们知道,EditText有一个 android:focusable=""的属性,但是如果你在edittext中直接将这个属性设置为true的话,点进去软键盘确实不会再弹出,但是EditText相应的也失去了聚焦,即无论你怎么点击它都不会有反应,这也就失去了EditText的原本的作用。那么要解决这个问题其实很简单,只需在EditText的父控件中加上这两行代码即可:

android:focusable="true"

android:focusableInTouchMode="true"

完整布局:

<RelativeLayout
android:background="@drawable/holiday_search"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:layout_marginLeft="50dp"
android:layout_alignParentRight="true"
android:layout_marginRight="20dp"
android:layout_centerVertical="true"
android:focusable="true"
android:focusableInTouchMode="true"
>
<ImageView
android:layout_alignParentLeft="true"
android:layout_marginLeft="5dp"
android:layout_centerVertical="true"
android:layout_width="20dp"
android:layout_height="20dp"
android:gravity="center_vertical"
android:background="@drawable/abs__ic_search"
/>
<EditText
android:singleLine="true"
android:textSize="13sp"
android:hint="输入景点名或城市名"
android:background="#00ff00ff"
android:gravity="center_vertical"
android:layout_alignParentLeft="true"
android:layout_marginLeft="30dp"
android:layout_width="fill_parent"
android:layout_height="30dp"
/>
<ImageButton
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:layout_centerVertical="true"
android:background="@drawable/abs__ic_voice_search_api_holo_light"
/>
</RelativeLayout>

那么为什么这样加就没有问题了呢?我们知道父控件实际上并不需要获得聚焦,我们将父控件的focusable设置为false之后就使得整个父控件属于失去聚焦的状态,当我们点击跳转时软键盘也就不会再自动弹出,相应的,当我们需要对EditText进行编辑时也不会有影响。

最新文章

  1. 学习 opencv---(6)玩转opencv源代码:生成opencv 工程解决方案与opencv 源码编译
  2. 仿【Emmet】转【HTML】功能
  3. JMeter学习-020-JMeter 监听器之【聚合报告】错误率、吞吐量、传输速率实例计算
  4. phpmailer 参数使用说明
  5. (VS) TFS lost mapping suddenly.
  6. Winform开发几个常用的开发经验及知识积累(一)
  7. Linux下oracle导入(exp)导出(imp)出现&quot;Failed to open ...for reader/write&quot;错误
  8. 运算符优先级 (Transact-SQL)
  9. Hadoop MapReduce编程的一些个人理解
  10. Java中读取某个目录下的所有文件和文件夹
  11. 实战-Mysql主从复制
  12. linux的定时任务服务crond(crontab)服务
  13. ejs常用语法
  14. MySQL执行语句的顺序
  15. hibernate多对多映射文件的配置
  16. linux下对clamav杀毒软件的安装和配置
  17. angularjs的一些问题
  18. js日期的格式化
  19. with 重写enter exit 方法
  20. (转)SQL知识_Sql日期时间格式转换

热门文章

  1. ios 微信细节
  2. ZipArchive 的使用
  3. C# GET 和 SET作用
  4. (转)Redis 集群方案
  5. [译]JavaScript检测浏览器前缀
  6. css3学习笔记之文本效果
  7. 方法:怎么用ionic命令行调试你的ionic app
  8. 关键字 virtual
  9. 《QQ欢乐斗地主》山寨版
  10. Windows内存原理与内存管理