本文介绍了在将错误设置为特定的textinputlayout(其中包含edittext)时,如何不更改标签的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我在其中使用Textinputlayout和edittext,问题是当我在验证时将错误设置为textinputlayout时,它会将提示标签的颜色也更改为红色.当出现错误时,我想用另一种颜色代替红色,只有下划线颜色和错误文本应该变成红色.

I am using a Textinputlayout and edittext inside it, problem is when I set the error to the textinputlayout at the time of validations , it changes the color of my hint label also to red. I want to put another color instead of that red color when error comes.Only the underline color and error text should turn to red.

上面的图片所示是问题所在,我不希望电子邮件标签为红色.

above shown in the pic is the problem, I dont want the email label with red color.

下面是我的代码.

     <android.support.design.widget.TextInputLayout
            android:layout_marginTop="30dp"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:layout_marginBottom="15dp"
 app:errorTextAppearance="@style/error_appearance"
        app:hintTextAppearance="@style/TextLabel1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/et1"
            android:padding="0dp">

        <EditText
            android:id="@+id/email"
            android:hint="Email"
            android:textColorHint="#3F4B5B"
            android:maxLines="1"
            android:inputType="text"
            android:textSize="15sp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

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


#java file


#Declarations
 private TextInputLayout emailerror;
 private EditText Email;

#On create
    Email=(EditText) findViewById(R.id.email);
     emailerror=(TextInputLayout) findViewById(R.id.et1);

#Inside validation method
 emailerror.setError("Enter a valid email");

Style.xml

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    <style name="AppTheme.NoActionBar" parent="Base.Theme.AppCompat.Light.DarkActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
         TextInputLayout text color
        <item name="colorControlNormal">#e0e0e0</item>
        <item name="colorControlActivated">#52AF44</item>
        <item name="android:textColorHint">#3F4B5B</item>
        <item name="android:windowFullscreen">true</item>
    </style>


<!--    <style name="error" parent="@android:style/TextAppearance">
        <item name="android:textColor">#ff0000</item> &lt;!&ndash;apply the color you wat here &ndash;&gt;
        <item name="android:textColorHint">#3E4A58</item>
       &lt;!&ndash; <item name="android:textColorHint">#3a52a6</item>&ndash;&gt;
       &lt;!&ndash; <item name="android:textSize">12dp</item>&ndash;&gt;
    </style>-->

    <!--<style name="Widget.Design.TextInputLayout" parent="AppTheme">
        <item name="hintTextAppearance">@style/TextLabel1</item>
        <item name="errorTextAppearance">@style/error_appearance</item>
        <item name="counterTextAppearance">@style/TextAppearance.Design.Counter</item>
        <item name="counterOverflowTextAppearance">@style/TextAppearance.Design.Counter.Overflow</item>
    </style>-->

    <style name="error_appearance" parent="@android:style/TextAppearance">
        <item name="android:textColor">@color/colorAccent</item>
    </style>

    <style name="TextLabel1" parent="TextAppearance.Design.Hint">
        <item name="android:textColor">@color/colorPrimaryDark</item>
        <item name="android:textSize">16sp</item>
    </style>

    <style name="ToolbarColoredBackArrow" parent="AppTheme">
        <item name="android:textColorSecondary">@color/white</item>
    </style>

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

    <style name="Widget.App.Spinner" parent="@style/Widget.AppCompat.Spinner">
        <item name="overlapAnchor">true</item>
        <item name="android:background">@drawable/spinner_background</item>
    </style>

</resources>

推荐答案

您需要使用自定义样式覆盖文本输入布局的默认样式.

You need to override text input layout default style, with your customstyle.

styles.xml

styles.xml

<resources>

 <style name="TextLabel">
    <item name="android:textColorHint">@color/colorPrimary</item> <!-- Your Hint Color -->
    <item name="android:textSize">18sp</item>
    <item name="colorAccent">@color/colorPrimary</item>
    <item name="colorControlNormal">@color/colorPrimary</item>
    <item name="colorControlActivated">@color/colorPrimary</item>
</style>

<style name="error_appearance" parent="@android:style/TextAppearance">
    <item name="android:textColor">@color/colorAccent</item>
</style>

</resources>

activity_layout.xml

activity_layout.xml

        <android.support.design.widget.TextInputLayout
            android:id="@+id/input_layout_mobile"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:theme="@style/TextLabel"
            app:errorTextAppearance="@style/error_appearance">

            <EditText
                android:id="@+id/edt_mobile"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:drawableLeft="@drawable/ic_phone_iphone_black_24dp"
                android:drawablePadding="8dp"
                android:drawableTint="@color/colorPrimary"
                android:hint="@string/email"
                android:inputType="number"
                android:textColor="#000" />
        </android.support.design.widget.TextInputLayout>


重点:


Focused:

没有重点:

错误消息:

这篇关于在将错误设置为特定的textinputlayout(其中包含edittext)时,如何不更改标签的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 20:26