Android让EditText失去焦点避免自动弹出输入法

来源:互联网 发布:学生就业压力大数据 编辑:程序博客网 时间:2024/05/22 14:38

如果一进去activity,EditText就获取焦点,弹出输入法界面,无疑是很影响美观的。关于让EditText失去焦点,网上比较多的做法是添加一个visibility=gone的Textview.然后让这个textView获取焦点。不知道是我人品不好还是怎么的。我这样做不行,后来采用另外一种做法,就是在其父组件(布局)上添加以下两句代码:

[java] view plain copy 在CODE上查看代码片派生到我的代码片
  1. android:focusable="true"     
  2. android:focusableInTouchMode="true"  

比如:
[html] view plain copy 在CODE上查看代码片派生到我的代码片
  1. <RelativeLayout  
  2.         android:layout_width="match_parent"   
  3.         android:layout_height="40dp"  
  4.         android:gravity="center_vertical"  
  5.         android:background="#ffffff"  
  6.         android:focusable="true"   
  7.         android:focusableInTouchMode="true"  
  8.     >  
  9.     <EditText   
  10.         android:layout_alignParentLeft="true"  
  11.         android:id="@+id/searchWordET"  
  12.         android:layout_width="match_parent"  
  13.         android:layout_height="wrap_content"  
  14.         android:background="#ffffff"  
  15.         android:hint="姓名 单位名称 QQ 手机 电话 地址"  
  16.         android:padding="10dp"  
  17.         android:imeOptions="actionSearch"  
  18.         android:singleLine="true"   
  19.         android:textSize="13sp" />  
  20. </RelativeLayout> 
0 0
原创粉丝点击