Установка нарисованного значка не работает со мной на android - PullRequest
0 голосов
/ 05 марта 2020

Я использую функцию setCompoundDrawablesRelativewithIntrinsicBounds, но ничего, что я делаю, чтобы исправить это, похоже, не работает.

Мой код MainActivity:

 private fun setIcons() {

        val view = findViewById(R.id.Head) as? TextView

        view?.setCompoundDrawablesRelativeWithIntrinsicBounds(R.drawable.therm, 0, 0, 0)

    }

Я вызываю эту функцию в onCreate

Мой XML код:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <androidx.cardview.widget.CardView
        android:layout_margin="@dimen/cardview_default_elevation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <LinearLayout
            android:padding="16dp"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:id="@+id/Head"
                android:textColor="@android:color/holo_red_dark"
                android:text="Heading"
                android:drawablePadding="10dp"
                android:textAppearance="@style/TextAppearance.AppCompat.Large"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

            </TextView>

            <TextView
                android:id="@+id/Desc"
                android:textAppearance="@style/TextAppearance.AppCompat.Large"
                android:textAlignment="textEnd"
                android:text="Description"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

            </TextView>

        </LinearLayout>
    </androidx.cardview.widget.CardView>
</LinearLayout>

1 Ответ

0 голосов
/ 05 марта 2020

попробуйте,

view?.setCompoundDrawablesRelativeWithIntrinsicBounds(AppCompatResources.getDrawable(view!!.context, R.drawable.therm), null, null, null)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...