90

Ich verwende die neue TextInputLayout aus der Design-Bibliothek. Ich bin in der Lage, es zu zeigen und die Farbe des Floating-Labels zu ändern. Leider ist der tatsächliche EditText Hinweis jetzt immer weiß.Change EditText Hinweisfarbe bei Verwendung von TextInputLayout

Ich habe versucht, die Hinweisfarbe in XML, Stile und programmgesteuert zu ändern und versuchte auch mit android.support.v7.widget.AppCompatEditText , aber der EditText Hinweis zeigt immer weiß.

Hier ist meine XML für meine TextInputLayout und EditText

<android.support.design.widget.TextInputLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android.support.design:hintTextAppearance="@style/GreenTextInputLayout"> 


    <EditText 

    android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/city" 
     android:textColorHint="@color/black" 
     android:hint="@string/city" /> 

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

Und hier ist der Stil, den ich für die TextInputLayout mit bin (ich versuchte, die Attribut schwarz zu machen, aber nicht für mich alles tun):

<style name="GreenTextInputLayout" parent="@style/TextAppearance.AppCompat"> 
    <item name="android:textColor">@color/homestory_green</item> 
</style> 
+0

Ich bin mit dem gleichen Fehler konfrontiert. Hinweis ist immer "WHITE" Farbe zunächst nach dem Berühren eines editText, es nimmt die von Ihnen definierte Farbe. Ich suche immer noch nach der Lösung. – ch3tanz

+0

Haben Sie die Antwort von @Ali Kabiri versucht? Es sieht so aus als wäre es eine bessere Lösung als meine. Meins war sehr spezifisch für mein Projekt. – SamIAmHarris

+0

Ich habe mein eigenes Thema und alle Farben sind in der style.xml definiert – ch3tanz

Antwort

4

Sieht aus wie die übergeordnete Ansicht, die einen Stil für eine 3rd-Party-Bibliothek hatte, der die EditText verursacht wurde, weiß zu sein.

android:theme="@style/com_mixpanel_android_SurveyActivityTheme" 

Sobald ich das entfernte alles funktionierte gut.

15

Ich bin mir nicht sicher, was verursacht Ihr Problem, diesen Code funktioniert perfekt für mich. Ich denke, es hat etwas mit der Verwendung des korrekten XML-Namespace zu tun (xmlns). Ich bin mir nicht sicher, ob die Verwendung von android.support.design ohne XML-Namespace-Attribut unterstützt wird. Oder es hat etwas mit dem textColorHint Attribut zu tun, das Sie im EditText selbst verwenden.

Layout:

<android.support.design.widget.TextInputLayout 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="5dp" 
    app:hintTextAppearance="@style/GreenTextInputLayout"> 

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

Stil:

<style name="GreenTextInputLayout" parent="@android:style/TextAppearance"> 
    <item name="android:textColor">#00FF00</item> 
</style> 
+2

Dies funktioniert immer noch wie das, was ich habe. Das Problem, das ich habe, ist, dass, bevor der Benutzer den EditText berührt, die EditText-Farbe weiß ist. Wenn der Benutzer den EditText berührt, ist das Label TextInputLayout grün und funktioniert einwandfrei. – SamIAmHarris

+0

das gleiche Problem hier @ user3520299, ein Glück, eine Lösung zu finden? – AhmedW

+0

Meine war ein einzigartiger Fall, weil die Elternansicht einen Themensatz hatte, der das Problem verursachte. Aber der Code, den ich auflege, funktioniert jetzt gut, nachdem ich dieses eine Thema entfernt habe – SamIAmHarris

97

definieren android:textColorHint in Ihrer Anwendung Thema:

<style name="AppTheme" parent="Theme.AppCompat.NoActionBar"> 
    <item name="colorPrimary">@color/primary</item> 
    <item name="colorPrimaryDark">@color/primary_dark</item> 
    <item name="colorAccent">@color/accent</item> 

    <item name="android:textColorHint">@color/secondary_text</item> 
</style> 

Source

+13

Hat bei mir nicht funktioniert. .. –

+0

@TheHungryAndroider hast du das Theme als Theme von acitvity gesetzt, wo du den Text bearbeitest? – mbelsky

+0

Es funktioniert für mich, aber die Farbe des Hinweises ist nicht bei der Erstellung von Fragmenten und Ansichten festgelegt, ich muss auf meinen 'EditText' klicken, damit die Hinweisfarbe auf allen Eingaben in der Ansicht gesetzt wird ... habe keine Korrektur gefunden dass ('requestFocus()' und 'performClick()' den Trick leider nicht machen). – Flawyte

4

versuchen, dies kann diese Hilfe

 edittext.addTextChangedListener(new TextWatcher() { 

     @Override 
     public void onTextChanged(CharSequence s, int start, int before, int count) { 
      // TODO Auto-generated method stub 
      Toast.makeText(getApplicationContext(), "onTextChanged", 2000).show();; 
      //newuser.setTextColor(Color.RED); 
      edittext.setHintTextColor(Color.RED); 

     } 

     @Override 
     public void beforeTextChanged(CharSequence s, int start, int count, 
       int after) { 
      // TODO Auto-generated method stub 

     } 

     @Override 
     public void afterTextChanged(Editable s) { 
      // TODO Auto-generated method stub 
      Toast.makeText(getApplicationContext(), "afterTextChanged", 2000).show();; 

     } 
    }); 
1
 <android.support.design.widget.TextInputLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

      <EditText 
       android:id="@+id/name" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:hint="Name" 
       android:textColor="@color/black" 
       android:textColorHint="@color/grey"/> 
     </android.support.design.widget.TextInputLayout> 

Verwenden textColorHint die Farbe einstellen, die Sie als die Hint-Farbe für den EditText. Die Sache ist, dass Hinweis im EditText nicht verschwindet, wenn Sie etwas eingeben, sondern sofort, wenn der EditText den Fokus bekommt (mit einer coolen Animation). Sie werden dies deutlich merken, wenn Sie den Fokus wegschalten und zum EditText.

11

Verweisen Sie den folgenden Code, der für mich arbeitete. Aber es beeinflußt alle Ihre Kontrollenfarbe.

<!-- In your style.xml file --> 
    <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> 
+0

sehr dank ist diese vollständige Antwort –

+0

diese akzeptiert werden soll - es zeigt, welche Eigenschaften für jeden gewöhnungs der Elemente, die wichtig sind. –

31

habe das gleiche Problem. Gelöst, indem diese Zeilen in Eltern Thema gesetzt werden.

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
    <item name="colorPrimary">@color/ColorPrimaryDark</item> 
    <item name="colorPrimaryDark">@color/ColorPrimaryDark</item> 
    <item name="colorAccent">@color/AccentColor</item> 
    <item name="android:windowTranslucentStatus">true</item> 

    <item name="android:textColorHint">@color/BackgroundtWhiteColor</item> 
    <item name="colorControlNormal">@color/BackgroundtWhiteColor</item> 
    <item name="colorControlActivated">#ff0000</item> 
    <item name="colorControlHighlight">@color/BackgroundtWhiteColor</item> 
    <!-- Customize your theme here. --> 
</style> 

Wenn Sie diese setzen

<item name="android:textColorHint">@color/BackgroundtWhiteColor</item> 
<item name="colorControlNormal">@color/BackgroundtWhiteColor</item> 
<item name="colorControlActivated">#ff0000</item> 
<item name="colorControlHighlight">@color/BackgroundtWhiteColor</item> 

in einem eigenen Stil und es auf TextInputLayout oder EditText es wird nicht angezeigt. Du hast HABE, um es im übergeordneten Thema der Anwendung zu platzieren.

+3

Es ist wirklich frustrierend, mit diesem Widget nicht mehrere Eingabestile in der App zu haben, aber soweit ich das beurteilen kann, hast du Recht. :/ – Turnsole

+2

Nun, es ist nicht notwendig, es in der ganzen Anwendung zu haben. Sie können dieses Thema nur auf eine Aktivität in Ihrer Manifestdatei anwenden. Und erstellen Sie ein weiteres Thema für den Rest Ihrer Aktivitäten. – RexSplode

+1

Endlich eine Antwort, die mein Problem gelöst hat !! Danke – cfl

8

Im TextInputLayout, die die EditText hält, fügen:

android:textColorHint="someColor" 
+0

Dies ist die richtige Antwort. – LukeWaggoner

47

erstellen benutzerdefinierte Stil in style.xml

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

dann in Ihrem Layout XML-Datei, fügen Thema Attribut als unter

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

Hoffnung das funktioniert

+1

Anzeige "Fehler beim Auflösen der Klasse EditText". Bitte helfen Sie! –

+0

Dies funktioniert nicht für API 19 – Coder

6

Nach dieser: https://code.google.com/p/android/issues/detail?id=176559

Try this:

<android.support.design.widget.TextInputLayout 
    android:textColorHint="#A7B7C2" 
    android:layout_width="match_parent" 
    android:layout_height="50dp"> 

    <EditText 
     android:id="@+id/et_confirm_password" 
     android:textColor="@android:color/black" 
     android:hint="Confirm password" 
     android:inputType="textPassword" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 
</android.support.design.widget.TextInputLayout> 

Es funktioniert in 23.1.1

24

hinzufügen textColorHint Eigenschaft zu Ihrem Text bearbeiten

android:textColorHint="#F6F6F6" 

oder welche Farbe Sie wollen

8

android: textColorHint = "# FFFFFF" irgendwann funktioniert und irgendwann nicht. Für mich unten Lösung funktioniert perfekt

Versuchen Sie den Code unten It In der XML-Datei funktioniert und Textlabel Thema wird in style.xml

<android.support.design.widget.TextInputLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:theme="@style/MyTextLabel"> 

    <EditText 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:hint="Floating Label" 
     android:id="@+id/edtText"/> 

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

In Styles Ordner Textlabel-Code

<style name="MyTextLabel" parent="TextAppearance.AppCompat"> 
    <!-- Hint color and label color in FALSE state --> 
    <item name="android:textColorHint">@color/Color Name</item> 
<!--The size of the text appear on label in false state --> 
    <item name="android:textSize">20sp</item> 
    <!-- Label color in TRUE state and bar color FALSE and TRUE State --> 
    <item name="colorAccent">@color/Color Name</item> 
    <item name="colorControlNormal">@color/Color Name</item> 
    <item name="colorControlActivated">@color/Color Name</item> 
</style> 

Wenn Sie definiert möchte nur die Farbe des Etiketts im falschen Zustand ändern, dann sind colorAccent, colorControlNormal und colorControlActivated nicht erforderlich

2
<item name="colorAccent">@android:color/black</item> 

Ihre colorAccent auf die gewünschte Farbe in Ihrem Theme ändern, wird dies Ihre EditText Linie, Cursor sowie Ihr Hinweis

ändern oder Sie können auch diesen Stil in Ihrem style.xml

<style name="TextLabel" parent="TextAppearance.AppCompat"> 
    <!-- Hint color and label color in FALSE state --> 
    <item name="android:textColorHint">@android:color/black</item> 
    <item name="android:textSize">20sp</item> 
    <!-- Label color in TRUE state and bar color FALSE and TRUE State --> 
    <item name="colorAccent">@android:color/black</item> 
    <item name="colorControlNormal">@android:color/black</item> 
    <item name="colorControlActivated">@android:color/black</item> 
</style> 

dann in Ihrem TextInputLayout können Sie es wie folgt

<android.support.design.widget.TextInputLayout 
      android:id="@+id/input_layout_password" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:theme="@style/TextLabel"> 
      <EditText 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:drawableLeft="@drawable/password" 
       android:drawableStart="@drawable/password" 
       android:maxLines="1" 
       android:hint="password" 
       android:inputType="textWebPassword" /> 

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

setzen Sie Hinweis Farbe auf TextInputLayout einstellen müssen.

6

Eine Menge Antworten, sondern brauchen nur eine Zeile für diese:

android: textColorHint = "# 000000"

<EditText 
     android:id="@+id/edtEmail" 
     android:textColorHint="#000000" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"/> 
2

Sie android:textColorHint="@color/color_black" innen TextInputlayout Es funktionierte für mich nutzen können.

<android.support.design.widget.TextInputLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="@dimen/dp_10" 
       android:textColorHint="@color/color_black" 
       app:hintTextAppearance="@style/TextLabel"> 

       <EditText 
        android:id="@+id/et_state" 
        style="@style/profile_editTextStyle" 

        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:hint="@string/billingState" 
        android:text="@string/billingState" 
        /> 
      </android.support.design.widget.TextInputLayout> 
Verwandte Themen