1

I have 2 modules:
app
- layout.xml
- styles.xml
- attrs.xml
core
- CustomComponent.java

In module core there is custom component, called CustomComponent, which I use in app module and where I want to set custom style, like 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 is my 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 would like to achieve following result:

After I set a style
customNS:chart_style="@style/MyCustomStyle"
In CustomComponent I would like to find this style, parse it and get all needed values.

But I cannot find working code for this.

Could you please advice how to achieve such result?

vetalitet
  • 703
  • 2
  • 10
  • 25

0 Answers0