Search code examples
androidtextnine-patch

Android - Best way to put text on a NinePatchDrawable


I need to put some text in the middle of a NinePatchDrawable. I would like that the NinePatchDrawable resizes itself according to the contained text. Googling around, I'm only able to get the 9-patch as Bitmap and then write on it. But in this way, it is just a bitmap and it is not handled as a NinePatchDrawable.

Hope this is enough clear.


Solution

  • Have you tried creating a text view, setting the text on that view, and then setting the background as the 9patch? The textview should expand to fit the text as necessary and then the 9patch will fit that view.