Android: combining text & image on a Button or ImageButton

I'm trying to have an image (as the background) on a button and add dynamically, depending on what's happening during run-time, some text above/over the image.

If I use ImageButton I don't even have the possibility to add text. If I use Button I can add text but only define an image with android:drawableBottom and similar XML attributes as defined here.

However these attributes only combine text & image in x- and y-dimensions, meaning I can draw an image around my text, but not below/under my text (with the z-axis defined as coming out of the display).

Any suggestions on how to do this? One idea would be to either extend Button or ImageButton and override the draw()-method. But with my current level of knowledge I don't really know how to do this (2D rendering). Maybe someone with more experience knows a solution or at least some pointers to start?

You can call setBackground() on a Button to set the background of the button.

Any text will appear above the background.

If you are looking for something similar in xml there is: android:background attribute which works the same way.

This method takes a drawable from your resources, draws some text on top of it and returns the new drawable. All you need to do is give it the resource id of your bubble, and the text you want on top. Then you can pass the returned drawable wherever you want it.

For users who just want to put Background, Icon-Image and Text in one Button from different files: Set on a Button background, drawableTop/Bottom/Rigth/Left and padding attributes.

        android:text="this is text"></Button>

For more sophisticated arrangement you also can use RelativeLayout (or any other layout) and make it clickable.

Tutorial: Great tutorial that covers both cases:

To send a group text using your Android phone, all you have to do is follow these steps: Launch your local “Messaging” app that comes pre-installed on your device. This app is not the Facebook Messenger app or WhatsApp or any messaging app that uses an internet connection to send messages. Create a new message.

There's a much better solution for this problem.

Just take a normal Button and use the drawableLeft and the gravity attributes.

  android:gravity="left|center_vertical" />

This way you get a button which displays a icon in the left side of the button and the text at the right site of the icon vertical centered.

android string. share | improve this question | follow | edited Jul 16 '16 at 4:32. Billal Begueradj. 9,711 16 16 gold badges 62 62 silver badges 88 88 bronze badges.

            android:textStyle="bold" />

In the previous installment of Android Layout Tricks, I showed you how to use the <include /> tag in XML layout to reuse and share your layout code. I also mentioned the <merge /> and it's now time to learn how to use it.

Just use a LinearLayout and pretend it's a Button - setting background and clickable is the key:

    android:orientation="horizontal" >

        android:src="@drawable/image" />

        android:text="Do stuff" />

In Excel, you can combine or merge text from two or more cells, as well as columns and rows,into one cell. If you have a lot of rows of data where you want to combine text, you can simply start typing the combined text in an adjacent column and Excel will fill in the rest for you.

* Combine videos with music. Trim and cut music, add multiple music parts * Adjust original video volume, adjust music volume separately * Mute video sound Add Text on Video & Sticker & Emoji & Watermark * Add text on video with font, color and style * Add emojis and stickers on video * Animate text and emojis * Add your own custom picture or

Android :: Combining Text And Image On Button Oct 7, 2009 I'm trying to have an image (as the background) on a button and add dynamically, depending on what's happening during run-time, some text above/over the image.

Combine text and numbers from different cells into the same cell by using a formula When you do combine numbers and text in a cell, the numbers become text and no longer function as numeric values. This means that you can no longer perform any math operations on them.