开发者

background picture for textview

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.setBackgroun开发者_Python百科dDrawable(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.


Use setBackgroundResource(), not setBackgroundDrawable.


I had the problem, and I've used your answer but didn't work. I solved it using the draw 9 patch padding pixels.


Use setBackgroundResource(R.drawable.image)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜