AutoCompleteTextView默认首次失去焦点

  1. 简介
    android中常用于在输入框中输入内容后自动提示,这种效果就可以使用AutoCompleteTextView来实现,也是和EditText的区别。
  2. 特点
    默认情况下直接进入其所在的页面后,获取焦点会直接弹出软键盘,这种效果在开发中可能体验不是很好,之前项目中需要的效果是,只有当用户点击了输入框后,才让软键盘弹出,这种效果肯能会比较好。
  3. 具体实现
    只需要在根布局添加 android:focusable="true"、android:focusableInTouchMode="true"两条语句即可。

自己之前代码如下

1. <LinearLayout  
  2.         android:layout_width="match_parent"  
  3.         android:layout_height="wrap_content"  
  4.         android:layout_marginTop="5dp"  
  5.         android:focusable="true"  
  6.         android:focusableInTouchMode="true"  
  7.         android:orientation="horizontal" >  
  8.   
  9.         <AutoCompleteTextView  
  10.             android:id="@+id/tv_poi_input"  
  11.             style="@style/common_text_style"  
  12.             android:layout_width="0dp"  
  13.             android:layout_height="wrap_content"  
  14.             android:layout_gravity="center_vertical"  
  15.             android:layout_weight="1"  
  16.             android:background="@drawable/poi_search"  
  17.             android:hint="@string/poi_input"  
  18.             android:paddingLeft="10dp"/>  
  19.   
  20.         <TextView  
  21.             android:id="@+id/tv_search"  
  22.             style="@style/common_text_style"  
  23.             android:layout_width="wrap_content"  
  24.             android:layout_height="wrap_content"  
  25.             android:background="@drawable/btn_white_selector"  
  26.             android:gravity="center"  
  27.             android:text="@string/search" />  
  28.     </LinearLayout>  
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。