Wie ändere ich die Textfarbe des Floating-Labels in Bezug auf das neue TextInputLayout
von Google?
Das Festlegen von colorControlNormal
, colorControlActivated
, colorControlHighLight
in Styles hilft nicht.
Das habe ich jetzt:
Probieren Sie den folgenden Code aus, der im Normalzustand funktioniert
<Android.support.design.widget.TextInputLayout
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
Android:theme="@style/TextLabel">
<Android.support.v7.widget.AppCompatEditText
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
Android:hint="Hiiiii"
Android:id="@+id/edit_id"/>
</Android.support.design.widget.TextInputLayout>
In Styles Folder TextLabel Code
<style name="TextLabel" parent="TextAppearance.AppCompat">
<!-- Hint color and label color in FALSE state -->
<item name="Android:textColorHint">@color/Color Name</item>
<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>
Zum Hauptdesign der App setzen, funktioniert es nur, nur Status hervorheben
<item name="colorAccent">@color/Color Name</item>
Update:
UnsupportedOperationException: Kann nicht in Farbe konvertiert werden: type = 0x2 in Api 16 oder darunter
<style name="TextAppearance.App.TextInputLayout" parent="@Android:style/TextAppearance">
<item name="Android:textColor">@color/red</item>
<item name="Android:textSize">14sp</item>
</style>
<Android.support.design.widget.TextInputLayout
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
Android:textColorHint="@color/gray" //support 23.0.0
app:hintTextAppearance="@style/TextAppearence.App.TextInputLayout" >
<Android.support.v7.widget.AppCompatEditText
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
Android:hint="@string/hint" />
</Android.support.design.widget.TextInputLayout>
Die Antwort gefunden, verwenden Sie das Android.support.design:hintTextAppearance
-Attribut, um Ihr eigenes Erscheinungsbild der Floating-Label festzulegen.
Beispiel:
<Android.support.design.widget.TextInputLayout
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
xmlns:app="http://schemas.Android.com/apk/res-auto"
app:hintTextAppearance="@style/TextAppearance.AppCompat">
<EditText
Android:id="@+id/password"
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
Android:hint="@string/Prompt_password"/>
</Android.support.design.widget.TextInputLayout>
Sie müssen nicht Android:theme="@style/TextInputLayoutTheme"
verwenden, um die Farbe der schwebenden Beschriftung zu ändern, da sie sich auf das gesamte Design der kleinen TextView auswirkt, die als Beschriftung verwendet wird. Verwenden Sie stattdessen app:hintTextAppearance="@style/TextInputLayout.HintText"
wo:
<style name="TextInputLayout.HintText">
<item name="Android:textColor">?attr/colorPrimary</item>
<item name="Android:textSize">@dimen/text_tiny_size</item>
...
</style>
Sag mir, ob die Lösung funktioniert :-)
Okay, ich fand diese Antwort sehr hilfreich und danke allen, die dazu beigetragen haben. Nur um etwas hinzuzufügen. Die akzeptierte Antwort ist in der Tat die richtige Antwort ... ABER ... in meinem Fall wollte ich die Fehlermeldung unterhalb des EditText
-Widgets mit app:errorEnabled="true"
implementieren, und diese einzige Zeile machte mein Leben schwierig. es scheint, dass dies das Thema überschreibt, das ich für Android.support.design.widget.TextInputLayout
ausgewählt habe, das eine andere Textfarbe hat, die durch Android:textColorPrimary
definiert ist.
Am Ende habe ich eine Textfarbe direkt auf das EditText
-Widget angewendet. Mein Code sieht ungefähr so aus:
styles.xml
<item name="colorPrimary">@color/my_yellow</item>
<item name="colorPrimaryDark">@color/my_yellow_dark</item>
<item name="colorAccent">@color/my_yellow_dark</item>
<item name="Android:textColorPrimary">@Android:color/white</item>
<item name="Android:textColorSecondary">@color/dark_gray</item>
<item name="Android:windowBackground">@color/light_gray</item>
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="Android:textColorHint">@color/dark_gray</item>
<item name="Android:colorControlNormal">@Android:color/black</item>
<item name="Android:colorControlActivated">@Android:color/white</item>
Und mein Widget:
<Android.support.design.widget.TextInputLayout
Android:id="@+id/log_in_layout_name"
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
app:errorEnabled="true">
<EditText
Android:id="@+id/log_in_name"
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
Android:layout_gravity="center_horizontal"
Android:textColor="@Android:color/black"
Android:ems="10"
Android:hint="@string/log_in_name"
Android:inputType="textPersonName" />
</Android.support.design.widget.TextInputLayout>
Jetzt wird anstelle der textColorPrimary
weiß die schwarze Textfarbe angezeigt.
Ich schlage vor, dass Sie ein Style-Theme für TextInputLayout erstellen und nur die Akzentfarbe ändern. Legen Sie übergeordnetes Element für Ihr App-Basisdesign fest:
<style name="MyTextInputLayout" parent="MyAppThemeBase">
<item name="colorAccent">@color/colorPrimary</item>
</style>
<Android.support.design.widget.TextInputLayout
Android:layout_width="fill_parent"
Android:layout_height="wrap_content"
Android:theme="@style/MyTextInputLayout">
In der neuesten Version der Unterstützungsbibliothek (23.0.0+) verwendet TextInputLayout
das folgende Attribut in XML, um die Farbe der Floating-Labels zu bearbeiten: Android:textColorHint="@color/white"
Anstelle von Brahmam Yamani antworte ich lieber Widget.Design.TextInputLayout als übergeordnetes Element. Dadurch wird sichergestellt, dass alle erforderlichen Elemente vorhanden sind, auch wenn nicht alle Elemente überschrieben werden. In der Yamanis-Antwort stürzt die App mit einer nicht auflösbaren Ressource ab, wenn setErrorEnabled (true) aufgerufen wird.
Ändern Sie einfach den Stil wie folgt:
<style name="TextLabel" parent="Widget.Design.TextInputLayout">
<!-- Hint color and label color in FALSE state -->
<item name="Android:textColorHint">@color/Color Name</item>
<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>
In meinem Fall habe ich diesen "app:hintTextAppearance="@color/colorPrimaryDark"
" in mein TextInputLayout-Widget eingefügt.
So ändern Sie die Farbe des Hinweises und bearbeiten die Farbe des Unterstrichs: colorControlActivated
So ändern Sie die Farbe des Zeichenindikators: textColorSecondary
So ändern Sie die Fehlernachrichtenfarbe: colorControlNormal
So ändern Sie den Tastentönungstaster für die Kennwortsichtbarkeit: colorForeground
Weitere Informationen zu TextInputLayout finden Sie unter http://www.zoftino.com/Android-textinputlayout-tutorial
<style name="MyAppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorControlActivated">#e91e63</item>
<item name="Android:colorForeground">#33691e</item>
<item name="colorControlNormal">#f57f17</item>
<item name="Android:textColorSecondary">#673ab7</item>
</style>
Ich habe versucht, Android zu verwenden: textColorHint im Android.support.design.widget.TextInputLayout es funktioniert gut.
<Android.support.design.widget.TextInputLayout
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
Android:textColorHint="@color/colorAccent">
<EditText
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
Android:hint="Hello"
Android:imeActionLabel="Hello"
Android:imeOptions="actionUnspecified"
Android:maxLines="1"
Android:singleLine="true"/>
</Android.support.design.widget.TextInputLayout>
Jetzt einfach colorAccent
und colorPrimary
zu verwenden, wird perfekt funktionieren.
sie sollten hier Ihre Farbe ändern
<style name="Base.Theme.DesignDemo" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#673AB7</item>
<item name="colorPrimaryDark">#512DA8</item>
<item name="colorAccent">#FF4081</item>
<item name="Android:windowBackground">@color/window_background</item>
</style>
<style name="AppTheme2" parent="AppTheme">
<!-- Customize your theme here. -->
<item name="colorControlNormal">#fff</item>
<item name="colorControlActivated">#fff</item></style>
fügen Sie dies zu Stilen hinzu und setzen Sie TextInputLayout Theam auf App2, und es wird funktionieren;)
um die Farbe der Beschriftung zu ändern, wenn Sie darauf fokussieren. das heißt, es einzugeben. Sie müssen angeben
<item name="Android:textColorPrimary">@color/yourcolorhere</item>
Nur eine Anmerkung: Sie müssen alle diese Implementierungen zu Ihrem Hauptthema hinzufügen.
Es arbeitet für mich ..... Fügen Sie in TextInputLayout eine Hinweisfarbe hinzu
<Android.support.design.widget.TextInputLayout
Android:textColorHint="#ffffff"
Android:id="@+id/input_layout_password"
Android:layout_width="match_parent"
Android:layout_height="wrap_content">
<EditText
Android:id="@+id/edtTextPassword"
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
Android:layout_marginTop="15dp"
Android:hint="Password"
Android:inputType="textPassword"
Android:singleLine="true"
/>
</Android.support.design.widget.TextInputLayout>
Ich löse das Problem ... Das ist Layout :
<Android.support.design.widget.TextInputLayout
Android:id="@+id/til_username"
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
Android:hint="@string/username"
>
<Android.support.v7.widget.AppCompatEditText Android:id="@+id/et_username"
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
Android:singleLine="true"
/>
</Android.support.design.widget.TextInputLayout>
Das ist Style:
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="colorAccent">@color/pink</item>
<item name="colorControlNormal">@color/purple</item>
<item name="colorControlActivated">@color/yellow</item>
</style>
Sie sollten Ihr Design in der Anwendung verwenden:
<application
Android:allowBackup="true"
Android:icon="@drawable/ic_launcher"
Android:label="@string/app_name"
Android:theme="@style/AppTheme" >
</application>
<com.google.Android.material.textfield.TextInputLayout
Android:hint="Hint"
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
Android:theme="@style/TextInputLayoutHint">
<androidx.appcompat.widget.AppCompatEditText
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
Android:inputType="text"
Android:maxLines="1"
Android:paddingTop="@dimen/_5sdp"
Android:paddingBottom="@dimen/_5sdp"
Android:textColor="#000000"
Android:textColorHint="#959aa6" />
</com.google.Android.material.textfield.TextInputLayout>
res/values / styles.xml
<style name="TextInputLayoutHint" parent="">
<item name="Android:textColorHint">#545454</item>
<item name="colorControlActivated">#2dbc99</item>
<item name="Android:textSize">11sp</item>
</style>