Android中如何取消调转界面后EditText默认获取聚焦问题
最近在做一个项目,当我点击跳转至一个带有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进行编辑时也不会有影响。
Android中如何取消调转界面后EditText默认获取聚焦问题的更多相关文章
- 【Android】Android中如何取消调转界面后EditText默认获取聚焦问题
参考资料: https://www.cnblogs.com/dream-cichan/p/aaaa.html http://blog.csdn.net/u013703461/article/detai ...
- Android中一张图片加载后所占用内存大小的获取与测试
Android程序中一旦加载的图片比较多,就有可能出现Out of Memory而导致程序崩溃.这个一方面是因为Android系统本身对于每个单独的进程有内存大小的限制(有16M,64M,128M,2 ...
- Android中自定义弹出PopupWindow后返回按键失效的问题解决
PopupWindow出现之后,默认的是所有的操作都无效的,除了HOME键.而且是可以操作后面的界面的.想要锁定后面的界面,很简单,只需要让PopupWindow是focusable的:popupWi ...
- Android中ViewPager+Fragment取消(禁止)预加载延迟加载(懒加载)问题解决方案
转载请注明出处:http://blog.csdn.net/linglongxin24/article/details/53205878本文出自[DylanAndroid的博客] Android中Vie ...
- Android中直播视频技术探究之---摄像头Camera视频源数据采集解析
一.前言 在视频直播中一般都是两种视频数据源,一个是摄像头数据,一个是录制桌面数据,而一般来说美女妹子直播都是来自于摄像头数据,游戏直播都是录制桌面数据的,那么今天就来看看第一个数据源数据采集分析,A ...
- Android中的通知—Notification 自定义通知
Android中Notification通知的实现步骤: 1.获取NotificationManager对象NotificationManager的三个公共方法:①cancel(int id) 取消以 ...
- Android中使用am命令实现在命令行启动程序详解
在Android中,除了从界面上启动程序之外,还可以从命令行启动程序,使用的是命令行工具am. 复制代码代码如下: usage: am [subcommand] [options] start an ...
- Android中EditText样式修改 聚焦光标、背景
在Android开发中,根据项目的需求,需要定制一些特殊的样式,例如:使用EditText时,聚焦时的背景及光标图片使用自定义而非android系统默认的.这两天,在项目中涉及此需求,现记录如下: 首 ...
- 关于android中EditText边框的问题 下划线
方法1 将edittext的style设置成?android:attr/textViewStyle 取消掉默认的样式,在设置background为@null 接下来就是一个空空的edittext了, ...
随机推荐
- (转)实战Memcached缓存系统(4)Memcached的CAS协议
1. 什么是CAS协议 很多中文的资料都不会告诉大家CAS的全称是什么,不过一定不要把CAS当作中国科学院(China Academy of Sciences)的缩写.Google.com一下,CAS ...
- 通过命令行连接oracle数据库/进入sql plus
1.直接打开SQL Plus登录,需要用户名和密码 开始->程序->Oracle->应用程序开发->sqlplus 我的电脑是“开始”->“Oracle - OraDb1 ...
- 算法 replace,replace_copy,back_inserter
replace (list.begin(), list.end(), , ); // replace any elements with value of 0 by 42 replace算法对输入序列 ...
- Z-Stack内部API 小结
Z-Stack是TI推出的全功能ZigBee协议栈,通过了ZigBee联盟的兼容性平台测试,包含如下几个组件. 1. HAL,硬件抽象层 2. OSAL,操作系统抽象层 3. ZigBee Stack ...
- [java学习笔记]java语言基础概述之运算符&程序流程控制&for循环嵌套
一.运算符 算数运算符 +,-,*,/,%,++,-- 1.+,-,*,/ 整数除以整数的结果为舍弃了小数部分的整数. 2.%:取余 %左右都为正数,左边小于右边结果为左边值,如,4%5=4 %左边大 ...
- TCL_事务控制语言
TCL transaction 事务 -- DML 定义为把一连串的操作作为单个逻辑工作单元处理 ----- 例如:银行转账 ...
- 2014-10 u-boot make xxx_defconfig 过程分析
/** ****************************************************************************** * @author Maox ...
- MySQL和Navicat使用总结
1.给字段设置默认字符值 ALTER TABLE `v_users`MODIFY COLUMN `picture` varchar(50) CHARACTER SET utf8 COLLATE utf ...
- VB.NET转C#代码的工具
比如VB.NET的代码: For Each prop In entity.Details.Properties.All(). OfType(Of Microsoft.LightSwitch.Detai ...
- delphi xe memory leak produced in WSDLLookup.pas
constructor TWSDLLookup.Create; begin FLookup := TDictionary<string, Variant>.Create; end; des ...