Monday, February 27, 2012

Setting the background image of an Android TextView

TextView displays text to the user and optionally allows them to edit it. A TextView is a complete text editor, however the basic class is configured to not allow editing; see for a subclass that configures the text view for editing.
In most cases u want add image as textView background. It's so easy. In layout xml file u must write:

android:text="A normal PNG file (*.png) will be loaded with an empty one-pixel border added around the image, in which you can draw the stretchable patches and content area. A previously saved 9-patch file (*.9.png) will be loaded as-is, with no drawing area added, because it already exists."
Then u will see result as following:

Of course u want see text in bubble :) For this u must edit image with 9patch
Then save image as 9.png and add to project drawable folder. Save project and run again if everything goes ok u must see result as following:

If u find this post useful then don't forget leavecomment :)


  1. Hi, thanks for great tutorial.

    May i know exactly where to put the 9.png?

  2. Not at all. Put your imagename.9.png file in the same folder which pngs are. So put in in your drawable folder and enjoy :)