button with image and text

2

I have a button that has the round outlines and when it is selected changes color. This button is associated with a certain text. I happen to want the button to show an image plus the text and I can not do it.

<Button
    android:text="Texto"
    android:background="@drawable/roundshape4_selector"
    android:layout_width="85dp"
    android:layout_height="85dp"
    android:gravity="center"
    android:id="@+id/texto"
    android:textStyle="bold"
    android:onClick="onClick"
    android:textColor="#B56EB6"
    android:textSize="12dp"/>

Here is the code of the roundshape4_selector used for when the button is pressed change color

<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:state_pressed="true" android:drawable="@drawable/roundshape4_pressed" />
    <item android:drawable="@drawable/roundshape4" />
</selector>

roundshape4_pressed

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="@color/pink"/>
    <corners android:radius="10dip" />
</shape>

This is where I am trying to put the image through the <img scr="@drawable/imagem48"></img> tag but only the text appears.

roundshape4

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >
    <img scr="@drawable/imagem48"></img>
    <corners android:radius="10dip" />
    <stroke android:color="@color/pink"
        android:width="6dip"></stroke>
    <solid android:color="@color/white"></solid>
</shape>

How can I make the button appear in the image and text at the same time?

    
asked by anonymous 07.08.2016 / 12:30

1 answer

2

You can add an image to a button using the following attributes:

android:drawableLeft
android:drawableRight
android:drawableTop
android:drawableBottom

Example to place an image placed on the left side of the text:

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/button_text"
    android:drawableLeft="@drawable/button_icon"
    ... />

More info on the documentation

    
07.08.2016 / 12:46