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

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

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

[java]
view plain
copy





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

比如:

[html]
view plain
copy





<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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: