Правильное рисование в неправильном положении - PullRequest
0 голосов
/ 08 апреля 2019

Я добавил нарисованные слева и справа программно, но нарисованный правый значок не справа.

enter image description here

Что я сделал:

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 выглядит так:

<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" />

1 Ответ

0 голосов
/ 09 апреля 2019

Проверьте документ SetCompundDrawablesWithIntrinsicBounds . Вы устанавливаете свой ничья в нижнем положении . Измените свой код, чтобы перевести ваше рисование в правильное положение :

editText.setCompoundDrawablesWithIntrinsicBounds((leftIcon != 0) ? getColouredIcon(context, leftIcon, color) : null,
        null,
        (rightIcon != 0) ? getColouredIcon(context, rightIcon, color) : null),
        null;
...