リストビュー ( listview_style.xml ) のすべての項目にストロークの輪郭を描画する形状 ( rect_shape.xml ) があります。このアウトラインは、現在のテーマのデフォルトのテキストの色と同じ色にする必要があります。
XMLで、ストロークの android:color 値を現在のテキストの色に設定する方法はありますか?
ここで独自の属性を設定しようとする同様の質問 ( How to get my own defined attribute value in my styleなど) を見てきましたが、これが私が望むものだとは思いません。とにかく試してみましたが、android:color 値を独自の定義済み属性に設定できませんでした ( android:color="?custom_stroke_color"
InflateException をスローします)。
ユーザーはテーマを動的に切り替えることができるため、rect_shape.xml@color/white
内の単一の事前定義された色 (または色リソースへの参照など) はオプションではありません。
助けていただければ幸いです...
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>