I Am using TextInputLayout. I try this but the icon is not shown. Help me to visible errorIcon in TextInputLayout.
I want to set a setError method to my EditText, with a custom icon instead of the default Android icon. So I tried this:
Thanks in Advance
<com.google.android.material.textfield.TextInputLayout
android:id="@ id/tilFirstName"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@ id/civProfileImage"
android:layout_marginStart="@dimen/margin_twenty_four"
android:layout_marginTop="40dp"
android:layout_marginEnd="@dimen/margin_twenty_four"
android:layout_marginBottom="@dimen/margin_sixteen"
android:hint="@string/first_name"
android:textColorHint="@color/text_input_layout_hint_color"
android:theme="@style/TextInputLayoutStyle"
app:boxCornerRadiusBottomEnd="5dp"
app:boxCornerRadiusBottomStart="5dp"
app:boxCornerRadiusTopEnd="5dp"
app:boxCornerRadiusTopStart="5dp"
app:boxStrokeColor="@color/text_input_layout_stroke_color"
app:boxStrokeErrorColor="@color/colorRed"
app:errorTextColor="@color/colorRed"
app:hintEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:id="@ id/edtFirstlName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@#!$%"
android:enabled="false"
android:focusable="false"
android:fontFamily="@font/roboto_regular"
android:imeOptions="actionNext"
android:inputType="textPersonName"
android:textColor="@color/colorTextNormal"
android:textSize="@dimen/text_size_sixteen" />
</com.google.android.material.textfield.TextInputLayout>
val drawable = resources.getDrawable(R.drawable.ic_baseline_error) as Drawable
drawable.setBounds(0, 0, drawable.intrinsicWidth, drawable.intrinsicHeight)
tilFirstName.error = getString("Error", Drawable)
CodePudding user response:
Use the setErrorIconDrawable
method in the TextInputLayout
:
tilFirstName.error = "Error text!!";
tilFirstName.setErrorIconDrawable(R.drawable.xxxx);
CodePudding user response:
Try using app:errorIconDrawable
in the xml file or use setErrorIconDrawable(Drawable)
to the TextInputLayout in the kotlin file.