2016-05-01 10 views
1

最大長のとき文字カウンタが浮動ラベルの色を変更しますが、setError()を呼び出すと変更されません。setError()を呼び出すときにTextInputLayoutのフローティングラベルの色を変更する方法

Screenshot

私はapp:errorTextAppearance="@style/MyErrorText"を試してみました。

スタイル/ MyErrorText:

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

そして私もsetErrorEnabled(true)を試してみました。しかし、彼らは変わらなかった。 setError()を呼び出すときに浮動ラベルの色を変更する方法はありますか?


XMLコード:

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

スタイル/ CustomTilTheme:

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

Javaコード:

...... 

    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")); 
    } 

    ...... 

私は

を使用しています210
  • サポートライブラリ23.3.0
  • SDKツール25.1.3
  • SDKプラットフォームツール23.1
  • ビルド・ツール23.0.3

このアプリは、Nexus 5のAPI23(公式のAndroidエミュレータ)上で動作します。

+0

このリンクを試すことができます。 http://stackoverflow.com/a/32818303/5744335 – Arshak

答えて

0

あなたは青にTextInputLayout浮動ラベルの色に変更した場合:

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

申し訳ありませんが、私はあなたがこの

を試すことができ、写真をアップロードカントを特にこのクイック答えは、あなたがthis answer

のように、より詳細なスタイルを作成することができますです
関連する問題