【Android開發那點破事】Android EditText不彈出輸入法焦點問題

在我們的應用中,有時候一進入一個頁面, EditText默認就會自動獲取焦點。彈出輸入法框,用戶體驗很不好,

那麼如何取消這個默認行爲呢?其實很簡單:在其父控件下,添加如下的屬性,就可以完美解決。

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

比如我的代碼:

<!-- search bar -->
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="50dip"
        android:background="@drawable/common_top_bar_bg"
        android:gravity="center"
        android:orientation="horizontal" 
        android:focusable="true"   
	android:focusableInTouchMode="true">

        <EditText
            android:id="@+id/edit_search"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:drawableRight="@drawable/category_search_btn"
            android:gravity="left|center"
            android:hint="@string/search_placeholder"
            android:textAppearance="?android:textAppearanceMedium" />
    </LinearLayout>
    <!-- search bar -->

好了今天這個破事就到這裏,其實android開發就這麼點破事。關於其他破事,見專欄:

更多Android開發的破事,請看專欄:《Android開發那點破事》


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章