溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Android取消EditText自動獲取默認焦點

發布時間:2020-10-02 14:08:30 來源:腳本之家 閱讀:695 作者:ganchuanpu 欄目:移動開發

最近在通訊錄新建聯系人=中,一進入一個頁面, 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>

以上就是本文的全部內容,希望本文的內容對大家的學習或者工作能帶來一定的幫助,同時也希望多多支持億速云!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女