goodm
goodm

Reputation: 7295

How to add background to textview

How to add background to textview (png with white cloud) that the background will stretch depending of text length. Thanks

Upvotes: 0

Views: 1167

Answers (2)

Bruno Oliveira
Bruno Oliveira

Reputation: 5076

You should add the image as a resource to your res/drawable folder (I recommend providing resolution-specific versions on res/drawable-ldpi, res/drawable-mdpi, res/drawable-hdpi, etc). Then, you can set the TextView's background by setting the android:background property to something like "@drawable/clouds".

However, I really recommend that you think about your application's design as a whole before applying backgrounds to specific components. Think about what your application will look like as a whole. Adding complex graphics as a background to text individual components may not be aesthetically pleasant.

A very good read on Android interface design: http://developer.android.com/design/index.html

Upvotes: 2

FoamyGuy
FoamyGuy

Reputation: 46856

You should really work to increase your accept rate. You are far more likely to get the kind of help you want on StackOverflow if you a decent accept rate. At the very least you want to get yourself above 0%. Check out the FAQ for some nice pointers

In the meantime check out an overview of 9-patch graphics here

You can use them to create the effect you are after. The image will grow in the regions that you specify to fill up all the space that the content takes up.

Inside your xml you can set it to a TextView with;

android:background="@drawable/yourimagename"

and just replace yourimagename, with the name of the resulting png file that you put in the drawables folder.

Upvotes: 2

Related Questions