Android取消EditText自動擷取焦點預設行為,androidedittext
最近在通訊錄建立連絡人=中,一進入一個頁面, EditText預設就會自動擷取焦點,很是鬱悶, 如何讓EditText不自動擷取焦點?
那麼如何取消這個預設行為呢?
在網上找了好久,有點 監聽軟鍵盤事件,有點 調用 clearFouse()方法,但是測試了都沒有! xml中也找不到相應的屬性可以關閉這個預設行為
解決之道:在EditText的父級控制項中找一個,設定成
android:focusable="true" android:focusableInTouchMode="true"
demo.xml:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ffffff" android:baselineAligned="false" android:focusable="true" android:focusableInTouchMode="true" > <RelativeLayout android:layout_width="250dp" android:layout_height="wrap_content" android:id="@+id/txtLayout" android:layout_marginTop="20dp" android:layout_centerHorizontal="true" > <EditText android:layout_width="fill_parent" android:layout_height="35dp" android:id="@+id/editPhone" android:phoneNumber="true" android:text="@string/txtaddPhone" android:textColor="#D8D8D8" android:background="@drawable/txtupbg" android:textSize="15dp" /> </RelativeLayout> </RelativeLayout>