小编Ume*_*mek的帖子

如何获取(引用)XML中的当前主题默认文本颜色

我有一个shape(rect_shape.xml),它在listview(listview_style.xml)的每个项目中绘制一个笔画轮廓.此轮廓应具有与当前主题的默认文本颜色相同的颜色.

在XML中,有没有办法将笔画的android:颜色值设置为当前文本颜色?

我在这里看到了一些类似的问题(比如如何在我的风格中获得我自己定义的属性值),这些问题试图设置一个自己的属性,但我认为这不是我想要的.无论如何我尝试了但我无法将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>
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

的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>
Run Code Online (Sandbox Code Playgroud)

resources android themes

5
推荐指数
1
解决办法
1176
查看次数

标签 统计

android ×1

resources ×1

themes ×1