您的位置:首页 > 移动开发 > Android开发

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

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

android:focusable="true"   
android:focusableInTouchMode="true"


比如:

<RelativeLayout
	    android:layout_width="match_parent" 
    	android:layout_height="40dp"
    	android:gravity="center_vertical"
    	android:background="#ffffff"
    	android:focusable="true" 
    	android:focusableInTouchMode="true"
    >
    <EditText 
        android:layout_alignParentLeft="true"
        android:id="@+id/searchWordET"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#ffffff"
        android:hint="姓名 单位名称 QQ 手机 电话 地址"
        android:padding="10dp"
        android:imeOptions="actionSearch"
        android:singleLine="true" 
        android:textSize="13sp" />
</RelativeLayout>


事情完美解决!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: