android - i want to change the position of request focus error icon so that it does not shows over the toggle icon for password

Viewed 355

image description

here is my edit text xml code

<android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:passwordToggleEnabled="true"
            android:theme="@style/TextLabel1">

<EditText
            android:id="@+id/editText4"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textCursorDrawable="@drawable/color_cursor"/>
</android.support.design.widget.TextInputLayout>

my class code for edit text

if (PassWordSignUp.length()<6) {
    PassWordSignUp.setError("Your password is less than 6 characters!");
    PassWordSignUp.requestFocus();
}
1 Answers

I was looking for an answer as well, and I got it. You can set your own drawable (which has margin) to be there instead of the red exclamation point icon.

How to make that customised icon with margin. First, you create a new Vector Asset with the icon you would like.

Drawable -> new -> Vector Asset -> choose your icon -> Next -> Finish

Now create completely new drawable which will access the vector icon. Plus you will now add the margin.

    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:right="32dp" //Adding the margin
            android:drawable="@drawable/the_name_of_your_vector_icon"/> //Accessing the vector icon
    </layer-list>

You have your XML resources. Now just display your newly (with margin) created icon instead of the normal one.

    Drawable customisedErrorIcon =
            getResources().getDrawable(R.drawable.your_new_error_icon);

    if (customisedErrorIcon != null) {
        customisedErrorIcon.setBounds(0, 0,
                customisedErrorIcon.getIntrinsicWidth(),
                customisedErrorIcon.getIntrinsicHeight());
    }

    yourEditText.setError("Error message", customisedErrorIcon);

This is how you set a customised drawable to be an error icon. And this is the result.

enter image description here

Related