开发者

Accessing style items by style ID

开发者 https://www.devze.com 2023-01-25 19:40 出处:网络
Any View have a constructor public View (Context context, AttributeSet attrs, int defStyle) which is called when View declared with a style attribute.

Any View have a constructor public View (Context context, AttributeSet attrs, int defStyle) which is called when View declared with a style attribute. So, if I have some class inherited from View class, I can access declared attributes (like android:layout_width or android:background) via AttributeSet attrs in a constructor. But when I move attributes to style I cannot see attributes and values exists in a style. I want to read items declared in style but I have only style ID in de开发者_C百科fStyle parameter. Is there some way to read style items using the style ID?


changing the style after creating the view is not supported .. so what you can do is :

1 - create a new android xml file of type values 2 - add new theme 3 - add your elements to that theme and their values and save the file

now when you are dynamically creating the new view you call the constructor that will allow to define a defStyle .. then you point to the style ID you have just created by pointing to R."the XML file name"."your style ID"

0

精彩评论

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