I
I
ivan05122020-07-29 23:06:59
Android
ivan0512, 2020-07-29 23:06:59

How to center an icon in a button?

You need to make a button with an icon.
I do it like this:

<Button
        android:layout_width="300dp"
        android:layout_height="70dp"
        android:background="@color/colorAccent"
        android:drawableLeft="@drawable/ic_dashboard_black_24dp"
        android:text="start"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

5f21d6b03ec2c486831096.jpeg
The picture is always pressed to the edge, but you want the picture and text to be in the center.
How can this be done?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
alekseyHunter, 2020-07-30
@alekseyHunter

Make a CardView and position an ImageView with a TextView. Add an OnClickListener, ripple effect, and you'll have a custom button.

Y
Yuri, 2020-07-30
@YuryBorodkin

ImageSpan

D
DARKENN, 2020-07-30
@DARKENN

Is there an ImageButton?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question