初始加载时edittext不自动获取焦点的方法

在做一个搜索功能时,刚进入界面,edittext直接自动获取焦点,这显然不是我想要的。

那么问题来了:如何关闭EditText自动获取焦点的?

尝试了好几个方法,在Java代码添加focus控制,在xml文件中的EditText控件中添加focusable约束等,都不适用于我的这个问题。

 

解决办法:在xml文件中EditText外框架里添加上android:focusable="true" android:focusableInTouchMode="true",这样问题就解决了。

 

[html]  view plain  copy
  1. <RelativeLayout    
  2.         android:id="@+id/title"    
  3.         android:layout_width="fill_parent"    
  4.         android:layout_height="wrap_content"    
  5.         android:layout_alignParentLeft="true"    
  6.         android:layout_alignParentRight="true"    
  7.         android:layout_alignParentTop="true"    
  8.         android:background="#F8F8FF"    
  9.         android:focusable="true"    
  10.         android:focusableInTouchMode="true"    
  11.         android:paddingBottom="6dp" >    
  12.     
  13.         <EditText    
  14.             android:id="@+id/search"    
  15.             android:layout_width="wrap_content"    
  16.             android:layout_height="wrap_content"    
  17.             android:layout_alignParentLeft="true"    
  18.             android:layout_marginLeft="10dp"    
  19.             android:layout_marginRight="5dp"    
  20.             android:layout_marginTop="5dp"    
  21.             android:layout_toLeftOf="@+id/auto_add"    
  22.             android:background="@drawable/rounded_edittext"    
  23.             android:drawableLeft="@drawable/search"    
  24.             android:ems="10"    
  25.             android:hint="@string/hint_search"    
  26.             android:imeOptions="actionSearch"    
  27.             android:inputType="text"    
  28.             android:singleLine="true"    
  29.             android:textSize="15sp" >    
  30.         </EditText>   

    本文转自 一点点征服   博客园博客,原文链接:http://www.cnblogs.com/ldq2016/p/8616545.html ,如需转载请自行联系原作者
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值