开发者

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

开发者 https://www.devze.com 2023-01-24 02:51 出处:网络
Howdy, I am currently generating some textviews in a loop. It would be great if I could apply a style to those textviews.

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

精彩评论

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