2016-01-29 9 views
0

У меня есть activity_edit_profile.xml макет, который включает фрагмент, но подсказка EditText постоянно отображается. Как мне избавиться от подсказки, когда поле EditText находится в фокусе или вставка текста?EditText hint keep показать

<?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

[EDIT]

Вот стиль 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 виджет. Добавить только 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" 
      />