2016-01-29 94 views
0

我有一個activity_edit_profile.xml嵌入一個片段的佈局,但EditText提示不斷顯示。如何在EditText字段處於焦點位置或插入文字時擺脫提示?EditText提示不斷顯示

<?xml version="1.0" encoding="utf-8"?> 
     <android.support.design.widget.CoordinatorLayout 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:tools="http://schemas.android.com/tools" 
      android:id="@+id/DrawerLayout" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:fitsSystemWindows="true" 
      tools:context="com.getbase.floatingactionbutton.sample.EditProfileActivity" 
      tools:ignore="MergeRootFrame"> 

      <include layout="@layout/fragment_edit_profile"/> 

    </android.support.design.widget.CoordinatorLayout> 

fragment_edit_profile.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       xmlns:tools="http://schemas.android.com/tools" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:padding="16dp" 
       android:orientation="vertical" 
       tools:context="com.getbase.floatingactionbutton.sample.EditProfileActivity$PlaceholderFragment"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 

     <android.support.design.widget.TextInputLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="10dp" 
      android:layout_weight="1" 
      android:theme="@style/TextLabel"> 

      <EditText 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:hint="First Name" 
       android:inputType="textCapWords" 
       android:nextFocusDown="@+id/register_input_lastname" 
       /> 
     </android.support.design.widget.TextInputLayout> 

     <android.support.design.widget.TextInputLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="10dp" 
      android:layout_weight="1" 
      android:theme="@style/TextLabel"> 

      <EditText 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:id="@+id/register_input_lastname" 
       android:hint="Last Name" 
       android:inputType="textCapWords"/> 
     </android.support.design.widget.TextInputLayout> 

    </LinearLayout> 

    <android.support.design.widget.TextInputLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="10dp" 
     android:theme="@style/TextLabel"> 

     <android.support.v7.widget.AppCompatEditText 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:hint="Email" 
      android:inputType="textEmailAddress" /> 
    </android.support.design.widget.TextInputLayout> 

    <android.support.design.widget.TextInputLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="10dp" 
     android:theme="@style/TextLabel"> 

     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:hint="Password" 
      android:inputType="textPassword" /> 
    </android.support.design.widget.TextInputLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 

     <android.support.design.widget.TextInputLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="10dp" 
      android:layout_weight="2" 
      android:theme="@style/TextLabel"> 

      <EditText 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:hint="Country Code" 
       android:inputType="number" 
       android:nextFocusDown="@+id/mobile_number"/> 

     </android.support.design.widget.TextInputLayout> 

     <android.support.design.widget.TextInputLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="10dp" 
      android:layout_weight="1" 
      android:theme="@style/TextLabel"> 

      <EditText 
       android:id="@+id/mobile_number" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:hint="Mobile" 
       android:inputType="phone"/> 

     </android.support.design.widget.TextInputLayout> 

    </LinearLayout> 
</LinearLayout> 

的EDITTEXT暗示持續顯示並具有TextInput重疊。

enter image description here

[編輯]

這裏是爲textLabel風格:

<style name="TextLabel" parent="@android:style/TextAppearance"> 
    <item name="android:textColorHint">@color/half_black</item> 
    <item name="android:textSize">14dp</item> 
    <item name="colorAccent">@color/ColorPrimary</item> 
    <item name="colorControlActivated">@color/ColorPrimary</item> 
</style> 
+0

它看起來問題是你的風格android:theme =「@ style/TextLabel」你能發佈代碼嗎? 刪除樣式,並檢查它會工作。 –

+0

我附上了主題風格。 –

回答

0

您可以將focusChangeListener您EditText領域。

我們以First Name爲例。將其分配爲編號firstName。現在,當它進入焦點時,將提示文本設置爲空字符串。當它失去焦點,改變提示文本回First Name

EditText firstName = (EditText)findViewById(R.id.firstName); 
firstName.setOnFocusChangeListener(new View.OnFocusChangeListener() { 
    public void onFocusChange(View v, boolean hasFocus) { 
     if(hasFocus) { 
      firstName.setHint(""); 
     } 
     else { 
      firstName.setHint("First Name"); 
     } 
    } 
}); 
0

可能的問題是與你的主題要設置爲TextInputLayout你的風格應該是喜歡 -

<style name="AppTheme.EditText"> 
     <item name="colorPrimary">#FF4081</item> 
     <item name="colorPrimaryDark">#3F51B5</item> 
     <item name="colorAccent">#303F9F</item> 
    </style> 
+0

謝謝。但它似乎不是一個造型問題。我嘗試應用你的風格,顏色的變化,但提示文本保持永久。 –

0

刪除您TextInputLayout的Widget。僅添加EditText。

<EditText 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:hint="First Name" 
      android:inputType="textCapWords" 
      android:nextFocusDown="@+id/register_input_lastname" 
      />