For clarification, the element name attribute should be the same as in the attribute attribute attrs.xml declare-styleable + ":" + attribute name.
For example:
attrs.xml:
<?xml version="1.0" encoding="utf-8"?> <resources> <declare-styleable name="com.chuck.norris"> <attr name="actionBarTextColor" format="color"/> </declare-styleable> </resources>
style.xml:
<?xml version="1.0" encoding="utf-8"?> <resources> <style name="myNewStyle"> <item name="android:textColor">#FFFF0000</item> <item name="com.chuck.norris:actionBarTextColor">#ffff0000</item> </style> </resources>
You can then apply this style to all actions using the theme in your manifest.xml file. Anywhere where there is a custom view that wants to use the "actionBarTextColor" attribute, you can use Java code:
TypedArray typedArray = context.obtainStyledAttributes(attrSet, R.styleable.com_chuck_norris); COLOR_ACTION_BAR_TEXT = typedArray.getColor(R.styleable.com_chuck_norris_actionBarTextColor, 0xff0000ff); typedArray.recycle();
I'm not sure why you cannot just define your schema in the style.xml file as mentioned above, but this is apparently a limitation of style.xml.
Shellum
source share