2016-05-01 2 views
1

Der Zeichenzähler ändert die Farbe der schwebenden Beschriftung bei maximaler Länge, aber der Aufruf setError() ändert es nicht.So ändern Sie die Farbe der schwebenden Beschriftung von TextInputLayout beim Aufrufen von setError()

Screenshot

Ich versuchte app:errorTextAppearance="@style/MyErrorText".

style/MyErrorText:

<style name="MyErrorText" parent="TextAppearance.AppCompat.Small"> 
    <item name="android:textColor">@color/error_color</item> 
</style> 

Und ich habe auch versucht, setErrorEnabled(true). Sie haben jedoch keine Änderung vorgenommen. Gibt es eine Möglichkeit, die Floating-Label-Farbe beim Aufruf von setError() zu ändern?


xml-Code:

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    xmlns:app="http://schemas.android.com/apk/res-auto"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:paddingLeft="@dimen/spacing_big" 
     android:paddingRight="@dimen/spacing_big" 
     android:paddingTop="@dimen/spacing_small"> 

     <android.support.design.widget.TextInputLayout 
      android:id="@+id/text_input_layout_name" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      app:counterEnabled="true" 
      app:counterMaxLength="25" 
      app:theme="@style/CustomTilTheme" 
      android:layout_marginBottom="@dimen/spacing_small"> 

      <android.support.design.widget.TextInputEditText 
       android:id="@+id/list_name" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:hint="@string/name_hint" 
       android:textSize="@dimen/text_normal"> 

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

     ...... 

    </LinearLayout> 
</ScrollView> 

style/CustomTilTheme:

<style name="CustomTilTheme" parent="Theme.Design.Light"> 
    <item name="colorControlActivated">@color/accent_color</item> 
</style> 

Java-Code:

...... 

    final TextInputLayout textInputLayoutName = (TextInputLayout) dialogLayout.findViewById(R.id.text_input_layout_name); 
    textInputEditText = (TextInputEditText) dialogLayout.findViewById(R.id.list_name); 
    textInputEditText.addTextChangedListener(new TextWatcher() { 
     @Override 
     public void beforeTextChanged(CharSequence s, int start, int count, int after) { 
     } 

     @Override 
     public void onTextChanged(CharSequence s, int start, int before, int count) { 
     } 

     @Override 
     public void afterTextChanged(Editable s) { 
      int size = s.length(); 

      if (size < 1) { 
       textInputLayoutName.setError("1文字以上入力してください"); 
      } else if (size > 25) { 
       textInputLayoutName.setError("25文字以内で入力してください"); 
      } else { 
       textInputLayoutName.setError(null); 
      } 
     } 
    }); 
    if (args == null) { 
     textInputLayoutName.setError("1文字以上入力してください"); 
    } else { 
     textInputEditText.setText(args.getString("list_name")); 
    } 

    ...... 

Ich verwende

  • Support Library 23.3.0
  • SDK-Tools 25.1.3
  • SDK Platform-Tools 23.1
  • Build-Werkzeuge 23.0.3

Diese App läuft auf Nexus 5 API23 (Official Android Emulator) .

+0

Sie können diesen Link versuchen, ich hoffe, es hilft Ihnen. http://stackoverflow.com/a/32818303/5744335 – Arshak

Antwort

0

Wenn Sie ändern TextInputLayout Floating-Label Farbe blau:

<android.support.design.widget.TextInputLayout 
       android:id="@+id/input_layout_register_firstname" 
       android:textColor="@color/blue" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"> 

Leider i Foto hochladen kippe können Sie versuchen, diese

Gerade dies ist eine schnelle Antwort, Sie detailliertere Stil wie this answer erstellen

Verwandte Themen