0

私は 2 つのモジュールを持っています:
app
- layout.xml
- styles.xml
- attrs.xml
コア
- CustomComponent.java

モジュールコアには、カスタムコンポーネントと呼ばれるカスタムコンポーネントがあり、アプリモジュールで使用し、カスタムスタイルを設定したい場合は、次のようになります

レイアウト.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

スタイル.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};
    **?????**
}

次の結果を達成したいと思います。


スタイルcustomNS:chart_style="@style/MyCustomStyle"を設定した後、
CustomComponent でこのスタイルを見つけて解析し、必要なすべての値を取得したいと思います。

しかし、これを実行するコードが見つかりません。

そのような結果を達成する方法を教えてください。

4

0 に答える 0