Zorgan
Zorgan

Reputation: 9143

drawableEnd attribute on Button doesn't accept shapes

Here is my Button:

<androidx.appcompat.widget.AppCompatButton
    android:id="@+id/status1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="@dimen/large_text"
    android:text="@string/offline"
    android:drawableEnd="@drawable/online_dot"
    android:drawableTint="@color/colorOnline"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"/>

online_dot.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape>
            <solid android:color="@color/colorOnline" />
            <stroke android:width="1dp" android:color="@color/colorLightBlack"/>
            <corners android:radius="@dimen/circle_radius" />
        </shape>
    </item>
</selector>

online_dot.xml doesn't show. If I change drawableEnd to an actual image (not drawable) then it works. But I want to show a shape.

How can I fix this?

Upvotes: 0

Views: 54

Answers (1)

Giorgio Antonioli
Giorgio Antonioli

Reputation: 16224

It happens because your shape hasn't a defined size. You have to specify the size inside online_dot.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape>
            <solid android:color="@color/colorOnline" />
            <stroke android:width="1dp" android:color="@color/colorLightBlack"/>
            <corners android:radius="@dimen/circle_radius" />
            <!-- Specify the shape size here. -->
            <size 
                android:height="20dp"
                android:width="20dp" />
        </shape>
    </item>
</selector>

Upvotes: 1

Related Questions