2016-09-18 61 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" 
    >