以编程方式创建一个Android查看带有特定风格 [英] Creating an Android View with a particular style programmatically
问题描述
其他<一href="http://stackoverflow.com/questions/2016249/how-to-programmatically-setting-style-attribute-in-a-view">questions说的风格,不能以编程方式设置,但查看
可以的初始化的一个风格时,它是从XML加载等。
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.
我怎么能初始化一个查看
与特定的风格programmaticly(而不是在XML)?我试图用<一个href="http://developer.android.com/reference/android/view/View.html#View%28android.content.Context,%20android.util.AttributeSet,%20int%29">View(Context背景下,ATTRS的AttributeSet,INT defStyle),但我不知道该怎么解析为第二个参数。传入空
导致查看
不显示
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
推荐答案
的AttributeSet包含XML指定属性的列表(例如:layout_width,layout_height等)。
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.
这篇关于以编程方式创建一个Android查看带有特定风格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!