當前主題默認文本顏色我有一個形狀( rect_shape.xml)繪製一個筆畫輪廓在ListView( listview_style.xml)的每一個項目。 此輪廓應具有與當前主題的默認文本顏色相同的顏色。如何獲得(參考)在XML
有沒有什麼辦法,在XML,把筆畫的android:color值設置爲當前的文字顏色?
我已經看到了一些類似的問題(如How to get my own defined attribute value in my style)在這裏它試圖設置一個自己的屬性,但我不認爲這是我想要的。 無論如何,我嘗試過,但我無法將android:color值設置爲我自己定義的屬性(android:color="?custom_stroke_color"
引發InflateException)。
因爲用戶能夠在主題之間切換動態地,一個單一的預定的顏色(或參考顏色資源例如@color/white
)在 rect_shape.xml不是一個選項。
感謝所有幫助...
rect_shape.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<stroke android:width="3dp"
<!-- should be the current default text color -->
android:color="#FFF" />
<solid/>
...
</shape>
listview_style.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/rect_shape" >
...
</LinearLayout>
的themes.xml
<resources>
<style name="DarkTheme" parent="@style/Theme.Sherlock">
<!-- default text color is white -->
...
</style>
<style name="LightTheme" parent="@style/Theme.Sherlock.Light">
<!-- default text color is black-->
...
</style>
</resources>