background picture for textview

Posted by AndyAndroid on Stack Overflow See other posts from Stack Overflow or by AndyAndroid
Published on 2011-01-04T16:48:05Z Indexed on 2011/01/04 16:53 UTC
Read the original article Hit count: 191

Hi,

I have a textview and a nine-patch image. Assigning this image in the xml editor to the tag "background" works as desired. Now I want to set this image dynamically in the coding, I thought

myTextView.setBackgroundDrawable(mydrawable);

would be the right thing to do. My png is in res/drawable. The API says that mydrawable needs to be an object of type drawable

 R.drawable.myninepatch

is of type int. So my problem is that I have to convert from that int to a drawable somehow. Then I thought I can use a constructor

NinePatchDrawable mydrawable = new NinePatchDrawable();

But I am again not able to construct such an object. Anyone an idea?

Thanks.

© Stack Overflow or respective owner

Related posts about android

Related posts about background