设置EditText自动失去焦点

来源:互联网 发布:sftp 批量下载 java 编辑:程序博客网 时间:2024/05/18 01:53

在布局中放一个EditText,如果没做处理的话,一进入就自动获取焦点,并弹出输入框,这时,需要在该EditText所依赖布局上添加:

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

有时候就算这么添加了,偶尔也会自动获取到焦点,为了保险起见,在该布局下面添加:

<requestFocus />

这样就可以了

例:

 <LinearLayout                android:id="@+id/homepage_search_linearlayout"                android:layout_width="match_parent"                android:layout_height="match_parent"                android:layout_centerVertical="true"                android:layout_marginBottom="6dp"                android:layout_marginTop="6dp"                android:layout_toLeftOf="@+id/homepage_citylocation"                android:layout_toRightOf="@+id/img_logo"                android:background="@drawable/homepage_search"                android:focusable="true"                android:focusableInTouchMode="true" >                <requestFocus />
0 0
原创粉丝点击