tags:

views:

260

answers:

1

Other questions say that the style cannot be set programmatically, but a View can be initialised with a style such as when it is loaded from XML.

How can I initialise a View with a particular style programmaticly (not in XML)? I tried using View(Context context, AttributeSet attrs, int defStyle), but I don't know what to parse in for the second argument. Passing in null results in the View not being displayed

A: 

AttributeSet contains the list of attributes specified in xml (ex. layout_width, layout_height etc).

If you are passing it as null, then you should explicitly set the height/width of view.

Karan
`AttributeSet` doesn't seem to have a constructor. Is it possible to build this without using xml?
Casebash
@Casebash AFAIK, you can not build the AttributeSet without using xml. You can set all the properties using the functions provided by the class.
Karan