android - how to set style for custom component? -
i have 2 modules:
app
- layout.xml
- styles.xml
- attrs.xml
core
- customcomponent.java
in module core there custom component, called customcomponent, use in app module , want set custom style, this
layout.xml
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:customns="http://schemas.android.com/apk/res-auto" ... <com.example.customcomponent android:id="@+id/chart" android:layout_width="fill_parent" android:layout_height="fill_parent" customns:chart_style="@style/mycustomstyle"/> </linearlayout
styles.xml
<style name="mycustomstyle"> <item name="android:textcolor">#efefef</item> <item name="android:background">#ffffff</item> <item name="android:text">this text</item> </style>
attrs.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <declare-styleable name="mycustomstyle"> <attr name="chart_style" format="reference"/> </declare-styleable> </resources>
customcomponent.java
public customcomponent(context context, attributeset attrs) { super(context, attrs); init(context); typedarray ta = context.obtainstyledattributes(attrs, new int[] {r.attr.chart_style}); int[] attrss = {android.r.attr.textcolor, android.r.attr.background, android.r.attr.text}; **?????** }
i achieve following result:
after set style
customns:chart_style="@style/mycustomstyle"
in customcomponent find style, parse , needed values.
but cannot find working code this.
could please advice how achieve such result?
Comments
Post a Comment