开发者

Create TextView ( in the code ) with style but without attributes

Howdy, I am currently generating some textviews in a loop. It would be great if I could apply a style to those textviews.

This style already containts all attributes so I w开发者_开发知识库ould not neet to set a Attribute, however if I do this

TextView counterTV = new TextView(activity,null, R.style.MenuField);

the TextView is created but there is are no styles applied to it :(.

It works flawlessly if I apply the same style to a textview in a XML File.


Try this little beauty:

TextView counterTV = new TextView(activity);
counterTV.setTextAppearance(activity, R.style.MenuField);

I have used it to apply the standard Android styles (like android.R.style.TextAppearance_Large) to TextViews before.


Have you tried setting the Layout Params?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜