2016-09-18 58 views
2

我正在使用EditText,但是當Activity已啓動時,我的EditText已被集中。我想刪除焦點,並使其可點擊編輯。從EditText刪除焦點,並保持可編輯

這是我的edittext的代碼。

<EditText 
      android:id="@+id/et_HotelLocation" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_margin="8dp" 
      android:drawableLeft="@drawable/ic_edit_location_black_24dp" 
      android:drawablePadding="8dp"/> 

回答

1

您可以創建虛擬佈局如下,你應該保持正好你的EditText上面,然後用nextFocusUp和nextFocusLeft如圖所示。

<LinearLayout 
      android:focusable="true" 
      android:focusableInTouchMode="true" 
      android:layout_width="0px" 
      android:layout_height="0px"/> 

     <EditText 

      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_margin="8dp" 
      android:id="@+id/et" 
      android:drawablePadding="8dp" 
      android:nextFocusUp="@id/et" 
      android:nextFocusLeft="@id/et" 
      app:met_floatingLabel="normal" /> 
0

添加以下兩個屬性在編輯文本

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

的父佈局,如果你的編輯文本是線性的佈局裏,你可以像這樣

<LinearLayout 
    android:focusable="true" 
    android:focusableInTouchMode="true" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 

<EditText 
      android:id="@+id/et_HotelLocation" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_margin="8dp" 
      android:drawableLeft="@drawable/ic_edit_location_black_24dp" 
      android:drawablePadding="8dp"/> 
</LinearLayout> 
0

這個問題已經已回覆here

也試試這個 - this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

否則,聲明在manifest文件的活動 -

<application android:icon="@drawable/icon" 
      android:label="@string/app_name"> 
<activity android:name=".Main" 
    android:label="@string/app_name" 
    android:windowSoftInputMode="stateHidden" 
    >