-2

Below is my code;

xml

  <android.support.design.widget.TextInputLayout
                android:id="@+id/emailTxtLayout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:theme="@style/TextLabel"
                android:layout_centerVertical="true"
                android:layout_toRightOf="@+id/button1">

                <android.support.design.widget.TextInputEditText
                    android:id="@+id/edt_editemail"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:digits="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890@."
                    android:fontFamily="@font/poppins_light"
                    android:hint="@string/e_mail"
                    android:inputType="textEmailAddress"
                    android:maxLines="1"
                    android:singleLine="true"
                    android:textColor="@color/gray"
                    android:textColorHint="@color/gray"
                    android:textSize="@dimen/sp_16" />

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

Style

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

<style name="ErrorText" parent="TextAppearance.Design.Error">
    <item name="android:textSize">16sp</item>
    <item name="android:textColor">@color/darkorange</item>
</style>

Code

EditText edt_editemail;
TextInputLayout emailTxtLayout;

 edt_editemail = findViewById(R.id.edt_editemail);
 emailTxtLayout = findViewById(R.id.emailTxtLayout);

Below dependencies which I used right now;

implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'

when I use below code and click on submit button, I got error;

emailTxtLayout.setError(getString(R.string.valid_email_id_error));

Error is below which I am getting;

java.lang.UnsupportedOperationException: Failed to resolve attribute at index 4: TypedValue{t=0x2/d=0x1010099 a=1} at android.content.res.TypedArray.getColor(TypedArray.java:462) at android.widget.TextView.(TextView.java:798) at android.widget.TextView.(TextView.java:732) at android.support.v7.widget.AppCompatTextView.(AppCompatTextView.java:87) at android.support.v7.widget.AppCompatTextView.(AppCompatTextView.java:83) at android.support.v7.widget.AppCompatTextView.(AppCompatTextView.java:79) at android.support.design.widget.IndicatorViewController.setErrorEnabled(IndicatorViewController.java:422) at android.support.design.widget.TextInputLayout.setErrorEnabled(TextInputLayout.java:938) at android.support.design.widget.TextInputLayout.setError(TextInputLayout.java:1055) at com.qltech.cunsumer.yupit.activities.RegisterActivity$4.onClick(RegisterActivity.java:307) at android.view.View.performClick(View.java:5675) at android.view.View$PerformClick.run(View.java:22646) at android.os.Handler.handleCallback(Handler.java:836) at android.os.Handler.dispatchMessage(Handler.java:103) at android.os.Looper.loop(Looper.java:203) at android.app.ActivityThread.main(ActivityThread.java:6251) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1075) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

Color.xml

<color name="colorPrimary">#FFFFFF</color>
<color name="colorPrimaryDark">#669b00</color>
<color name="colorAccent">#F05522</color>
<color name="darkorange">#F05522</color>
<color name="white">#FFFFFF</color>
<color name="black">#313131</color>
<color name="header_color">#eeeeee</color>
<color name="edit_text_line_color">#dddddd</color>
<color name="dark_black">#000000</color>
<color name="darkgreen">#99cc33</color>
<color name="green">#99cc33</color>
<color name="gray">#666666</color>
<color name="light_gray_b">#999999</color>
<color name="light_gray">#f5f5f5</color>
<color name="dark_gray">#e1e1e1</color>
<color name="transparent_color">#44000000</color>
Vishal Vaishnav
  • 3,346
  • 3
  • 26
  • 57

1 Answers1

0

Modify your layout like this

<android.support.design.widget.TextInputLayout
            android:id="@+id/emailTxtLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:theme="@style/TextLabel"
            android:layout_centerVertical="true"
            android:layout_toRightOf="@+id/button1"
            app:errorEnabled="true">

You need this attribute to show the error

app:errorEnabled="true"

then call,

emailTxtLayout.setError(getString(R.string.valid_email_id_error));
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
Manoj Perumarath
  • 9,337
  • 8
  • 56
  • 77