1
resposta

Definir um Button com Imagem e Texto

Quero definir um Botão com Imagem e Texto, como faço?

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="168dp"
        android:layout_height="35dp"
        android:text="Cálculo de Volume"
        android:textSize="19dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.498"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.051" />

    <TextView
        android:id="@+id/calculada"
        android:layout_width="117dp"
        android:layout_height="0dp"
        android:layout_marginStart="210dp"
        android:layout_marginTop="646dp"
        android:layout_marginEnd="232dp"
        android:layout_marginBottom="69dp"
        android:cursorVisible="false"
        android:visibility="invisible"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.46"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:ignore="MissingConstraints" />

    <EditText
        android:id="@+id/altura"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="numberSigned"
        android:text="Informe a Altura"
        android:textAlignment="center"
        tools:layout_editor_absoluteX="92dp"
        tools:layout_editor_absoluteY="327dp" />

    <ImageButton
        android:id="@+id/prisma_triangular"
        android:layout_width="38dp"
        android:layout_height="66dp"
        android:layout_marginStart="92dp"
        android:layout_marginTop="24dp"
        android:layout_marginEnd="281dp"
        android:scaleType="center"
        android:text="Prisma Triângular"
        android:textAlignment="textEnd"
        android:textDirection="firstStrongRtl"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/altura"
        app:srcCompat="@mipmap/pristma_triangular_foreground" />

</androidx.constraintlayout.widget.ConstraintLayout>
1 resposta

na tag do botao digite :

android: drawableLeft=@drawable/sua_imagem 
ou
android:drawableRight=@drawable/sua_imagem