如何更改TextInputLayout中浮动的标签颜色

时间:2016-04-25 21:24:07

标签: android

我正在尝试更改浮动标签“电子邮件”的颜色,如屏幕截图所示。

Login Screen with wrong floated label color

以下是布局XML的内容:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.premedios.streetler.LoginActivity">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="150dp"
    android:orientation="vertical"
    android:layout_marginTop="10dp">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="150dp"
        android:src="@drawable/logo"/>

</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp"
    android:orientation="vertical">
    <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/TextLabel">
        <EditText
            android:id="@+id/email"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/email_hint"/>
    </android.support.design.widget.TextInputLayout>
    <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/TextLabel">
        <EditText
            android:id="@+id/password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/password_hint"/>
    </android.support.design.widget.TextInputLayout>
    <Button
        android:id="@+id/login"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:background="@color/colorText"
        android:text="@string/LoginButtonText"
        android:textColor="@color/colorPrimaryDark"
        android:textSize="20sp"/>
    <com.facebook.login.widget.LoginButton
        android:id="@+id/facebook_login_button"
        android:layout_gravity="center_horizontal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:height="44dp"
        android:visibility="gone"/>
    <TextView
        android:id="@+id/signup"
        android:layout_width="match_parent"
        android:layout_height="44dp"
        android:layout_marginTop="10dp"
        android:gravity="center"
        android:text="@string/register_link_text"
        android:textSize="18sp"/>
</LinearLayout>

我想更改浮动标签颜色与提示颜色相同。任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:0)

使用this link

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

你只需要在textInputLayout

中使用这种风格