2017-11-13 9 views
1

私はhinttextの色を変更したいと思っています。テキストを入力するとヒントテキストの色は青色になります。他の賢明な色は灰色でなければなりません。edittextにはある値詳細については、hintTextの色は青でなければなりません。入力レイアウトトグルhintTextの色の変更

image1

究極の私はいくつかの値を含むエディットテキストの後にこれが欲しいです。

image2

これは私がこの問題を解決することができますどのように

image3

<style name="labelcolor" parent="Theme.AppCompat.Light.NoActionBar"> 
    <!-- Hint color and label color in FALSE state --> 
    <item name="android:textColorHint">#868686</item> 
    <item name="android:textSize">16sp</item> 
    <item name="android:paddingTop">5sp</item> 
    <!-- Label color in TRUE state and bar color FALSE and TRUE State --> 
    <item name="colorAccent">#0ea3ff</item> 
    <item name="colorControlNormal">#0ea3ffr</item> 
    <item name="colorControlActivated">#0ea3ff</item> 
</style> 

が私を助けてください、このコードを使用した後、私の現在の結果です。

+0

ヒントテキストは表示されないため、ヒントテキストの色を変更することはできません。入力したテキストの色を変更することができます。 –

+0

電子メールのラベルの色を変更する必要があります。 –

+0

この回答を確認するhttps://stackoverflow.com/a/30914037/1993001 –

答えて

1

変更TextInputLayoutルベル色Dynamicalyに影響を与え、私のために色に従って作業を渡してください。

public static void textInoutLayoutColor(TextInputLayout textInputLayout, @ColorInt int color) { 

    try { 
     Field fDefaultTextColor = TextInputLayout.class.getDeclaredField("mDefaultTextColor"); 
     fDefaultTextColor.setAccessible(true); 
     fDefaultTextColor.set(textInputLayout, new ColorStateList(new int[][]{{0}}, new int[]{ color })); 

     Field fFocusedTextColor = TextInputLayout.class.getDeclaredField("mFocusedTextColor"); 
     fFocusedTextColor.setAccessible(true); 
     fFocusedTextColor.set(textInputLayout, new ColorStateList(new int[][]{{0}}, new int[]{ color })); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
} 

このような色を変更してください。

input_layout= (TextInputLayout) findViewById(R.id.input_layout); 
    etuser_name.setOnFocusChangeListener(new View.OnFocusChangeListener() { 
     @Override 
     public void onFocusChange(View view, boolean hasfocus) { 
      if(hasfocus){ 
       textInoutLayoutColor(input_layout,getResources().getColor(R.color.bullet_color)); 
      } 
      else 
      { 
       if(etuser_name.getText().toString().trim().length()>0) { 
        textInoutLayoutColor(input_layout,getResources().getColor(R.color.bullet_color));; 
       } 
       else 
       { 
        textInoutLayoutColor(input_layout,getResources().getColor(R.color.hint_grey)); 
       } 
      } 
     } 
    }); 
+0

私のためにうまい解決策の仕事... –

0

怒鳴るとしてあなたを作成して、まずあなたがあなたを

android.support.design.widget.TextInputLayout textInputLayout =  (TextInputLayout) view.findViewById(R.id.textInputLayout); 

textInputLayout.setHintTextAppearance(R.style.Instyle); 

あなたTextInputLayoutを設定し、その後のstyles.xmlファイルにする必要があるよう怒鳴る

<android.support.design.widget.TextInputLayout 
      android:theme="@style/EditTextHint" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 
     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"/> 
</android.support.design.widget.TextInputLayout> 
+0

は同じ結果ではありません。 –

0

を、それを使用し

<style name="EditTextHint" parent="TextAppearance.AppCompat"> 
    <item name="colorAccent">@android:color/white</item> 
    <item name="android:textColorHint">@color/BackgroundtWhiteColor</item> 
    <item name="colorControlNormal">@color/BackgroundtWhiteColor</item> 
    <item name="colorControlActivated">@color/your color</item> 
    <item name="colorControlHighlight">@color/BackgroundtWhiteColor</item> 
</style> 

を試してみてくださいヒントカラーの色でスタイルを作成できます。あなたがのEditTextの値の入力を開始するとき

<style name="Instyle" parent="AppThemeLight"> 
    <itemname="android:textColorPrimary">@android:color/darker_gray</item> 
    <item name="android:textColor">@android:color/darker_gray</item> 
</style> 
+0

うまくいきません.. –

0

TextInputLayoutはhintTextColorにcolorAccentをとります。 青にしたい場合は、あなたのテーマに青色にcolorAccentを設定してください。 edittextに値がない場合は、hintTextColorをgreyに設定します。この

<android.support.design.widget.TextInputLayout 
        android:id="@+id/userNameTIL" 
        android:layout_width="match_parent" 
        android:layout_height="55dp" 
        android:background="@color/spinnerBg" 
        android:clipToPadding="false" 
        android:gravity="bottom" 
        android:paddingTop="4dp" 
        android:textColorHint="@color/grey"> /*Here it sets color to hintText when edittext has no value */ 

        <EditText 
         android:layout_width="match_parent" 
         android:layout_height="50dp" 
         android:layout_gravity="bottom" 
         android:background="@null" 
         android:hint="Username" 
         android:inputType="text" 
         android:maxLength="30" 
         android:paddingEnd="3dp" 
         android:paddingStart="25dp" 
         android:paddingTop="3dp" 
         android:singleLine="true" 
         android:textColor="@color/black" 
         android:textColorHint="@color/black" 
         android:textSize="20sp"/> 
       </android.support.design.widget.TextInputLayout> 
0
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar"> 
       <!--EditText hint color--> 
       <item name="android:textColorHint">@color/default_app_white</item>    <!-- TextInputLayout text color--> 
       <item name="colorControlActivated">@color/default_app_green</item> 
       <!-- EditText line color when EditText on-focus--> 
       <item name="colorControlHighlight">@color/default_app_green</item> 
       <!-- EditText line color when EditText in un-focus--> 
       <item name="colorControlNormal">@color/default_app_white</item> 
      </style> 
<!-- In your style.xml file --> 

のようにこれを試してみてください、それはのEditTextのフォーカスの変更の中で、あなたのアプリケーション全体

関連する問題