0

I have added drawable left and right programmatically but drawable right icon not in right.

enter image description here

What I did :

ReusableClass.setVectorDrawable(LoginActivity.this, R.drawable.ic_language_black_24dp, R.drawable.ic_arrow_drop_down_black_24dp, inputLanguage, R.color.colorAccent);

public static void setVectorDrawable(Context context, int leftIcon, int rightIcon, EditText editText, int color) {
    editText.setCompoundDrawablesWithIntrinsicBounds((leftIcon != 0) ? getColouredIcon(context, leftIcon, color) : null,
            null,
            null,
            (rightIcon != 0) ? getColouredIcon(context, rightIcon, color) : null);
}

public static Drawable getColouredIcon(Context context, int icon, int color) {
    Drawable drawable = VectorDrawableCompat.create(context.getResources(), icon, null);
    drawable = DrawableCompat.wrap(drawable);
    DrawableCompat.setTint(drawable, color);
    return drawable;
}

XML LOOKS LIKE THIS:

<EditText
            android:id="@+id/input_language"
            android:layout_width="@dimen/edittext_width"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:background="@color/bg_edittext"
            android:clickable="true"
            android:cursorVisible="false"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:hint="@string/hint_language"
            android:inputType="text"
            android:maxLines="1"
            android:padding="10dp"
            android:textColor="@android:color/black"
            android:textColorHint="@color/input_text_hint_bg" />
A J
  • 4,542
  • 5
  • 50
  • 80

1 Answers1

0

Check the document SetCompundDrawablesWithIntrinsicBounds. You set your drawable in bottom position. Change your code to put your drawable to right position:

editText.setCompoundDrawablesWithIntrinsicBounds((leftIcon != 0) ? getColouredIcon(context, leftIcon, color) : null,
        null,
        (rightIcon != 0) ? getColouredIcon(context, rightIcon, color) : null),
        null;
ToraCode
  • 421
  • 8
  • 19