Create a TextView (in code) with a style but no attributes

Howdy, I am currently creating several text views in a loop. It would be great if I applied style to these text comments.

This style already contains all the attributes, so I will not set the attribute, however, if I do

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

A TextView was created, but no styles are applied to it: (.

It works flawlessly if I apply the same style to the text view in the XML file.

+4
source share
2 answers

Try this little beauty:

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

I used it to apply standard Android styles (e.g. android.R.style.TextAppearance_Large ) before TextView before.

+3
source

Have you tried setting Layout Options?

0
source

All Articles