背景:給新屏幕添加了一個搜索的功能,但是一進入屏幕就彈出鍵盤,影響用戶操作。
原理:使EditText失去焦點,禁止彈出鍵盤。
方法:在其父控件添加如下屬性。
android:focusable="true"
android:focusableInTouchMode="true"
舉例:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ll_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:focusable="true"
android:focusableInTouchMode="true" >
<EditText
android:id="@+id/edt_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:hint="@string/str_input_hint"
android:paddingLeft="10dp"
android:paddingRight="20dp"
android:singleLine="true" />
<ImageView
android:id="@+id/iv_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="@drawable/delete" />
</RelativeLayout>
<Button
android:id="@+id/btn_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/str_search" />
</LinearLayout>
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。