开发者

how to translate XML layout background attribute value into code?

I'm sure this is really easy, but one of those hard to find things for beginners! Here's wha开发者_开发百科t I have in my layout XML file which I want to play around with programatically:

<View 
    android:layout_width="fill_parent" 
    android:layout_height="1dp" 
    android:background="?android:attr/listDivider" 
/> 

And here is how far I've gotten with the code:

View ruler = new View(this);
ruler.setBackgroundDrawable(????); //or is it setBackgroundResource?
parent.addView(ruler, 
               new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, 1));

I'm stuck on how to translate "?android:attr/listDivider" into code and which setter on the View object I'm interested in. Can anyone help with this? Thanks!


It is said here (in the "XML attributes" array) that android:background is equivalent to setBackgroundResource.

I guess you should try .setBackgroundResource(android.R.attr.listDivider).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜