更新:有CustomTextView定義。2個自定義屬性如果兩者都在XML它工作得很好定義。如果第一缺少它沒有給出第二個也是任何價值...如何獲取在xml佈局中定義的顏色屬性的引用?
<com.mycompany.projectname.MyCustomView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:extraColor="?someColor"
/>
這裏someColor是另一種顏色教師責任觀的不同的主題變化.. 我需要MyCustomView類extraColor自定義屬性的值...
目前獲得它如下:
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CustomTextView, defStyleAttr, 0);
a.getColorStat ELIST()不在這裏工作了......
CustomTextView定義爲:
<declare-styleable name="CustomTextView">
<attr name="state" format="boolean" />
<attr name="extraColor" format="reference|color" />
</declare-styleable>
更新:有CustomTextView定義2個自定義屬性.. 如果兩者都在XML定義它工作得很好。如果首先是缺少它沒有給出第二個也是任何價值...
你嘗試 「一getColorStateList(R.styleable.CustomTextView_extraColor)。」? –
a。 getColorStateList(R.styleable.CustomTextView_extraColor);工作良好..但只有當這兩個自定義屬性定義在xml .. – Awesome