5

I have a shape (rect_shape.xml) which draws a stroke outline in every item of a listview (listview_style.xml). This outline should have the same color like the default text color of the current theme.

Is there any way, in XML, to set the android:color value of the stroke to the current text color?

I've seen some similar questions (like How to get my own defined attribute value in my style ) around here which try to set an own attribute, but I don't think that this is what I want. Anyhow I tried that but I couldn't set the android:color value to my own defined attribute ( android:color="?custom_stroke_color" throws InflateException).

Because the user is able to switch between the Themes dynamically, one single predefined color (or reference to a color resource e.g. @color/white ) in rect_shape.xml is not an option.

Appreciate any help...

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>
Community
  • 1
  • 1
Umek
  • 103
  • 1
  • 5

1 Answers1

0

Accessing themed attributes in drawable XML files is only available in android 5.0 and up.

See This issue

Avi Shukron
  • 6,088
  • 8
  • 50
  • 84