最近在通訊錄新建聯系人=中,一進入一個頁面, 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>
以上就是本文的全部內容,希望本文的內容對大家的學習或者工作能帶來一定的幫助,同時也希望多多支持武林網!
新聞熱點
疑難解答