2013-07-24 88 views
2

我有两个基于holo的ABS风格,紫色和石灰,用户可以从设置中设置主题。风格选择器?

在我的布局中,我有一个带有自定义textAppearance的TextView,我想根据活动样式更改textAppearance。

(如紫色的主题被激活时,文本必须是白色的,如果石灰主题被激活时,文本必须是石灰)

有没有办法做到这一点从XML?

编辑

我很抱歉,如果标题有误导之嫌。

+2

你是什么意思与“活跃样式'? – Simon

+1

@simon我已更新我的问题 – jjdev80

回答

1

(如紫色的主题被激活时,文本必须是白色的,如果 石灰主题被激活时,文本必须是石灰)

试一下:

<style name="PurpleTheme" parent="..."> 
    <!-- define the style for the text appearance here. Following is an example --> 
    <item name="android:textAppearance">@style/MyWhiteText</item> 
</style> 

<style name="LimeTheme" parent="..."> 
    <!-- define the style for the text appearance here. Following is an example --> 
    <item name="android:textAppearance">@style/MyLimeText</item> 
</style> 

<style name="MyWhiteText" parent="@android:style/TextAppearance"> 
    <item name="android:textColor">@color/white</item> 
</style> 

<style name="MyWhiteText" parent="@android:style/TextAppearance"> 
    <item name="android:textColor">@color/lime</item> 
</style> 

或者,如果您不想将颜色设置为全部 TextViews然后执行此操作:

声明一个att ribute:

<attr name="myTextViewColor" format="reference" /> 

使用它像这样在你的主题:

<style name="PurpleTheme" parent="..."> 
    <item name="myTextViewColor">@color/white</item> 
</style> 

<style name="LimeTheme" parent="..."> 
    <item name="myTextViewColor">@color/lime</item> 
</style> 

现在,你可以这样设置特定的TextView的颜色:

<TextView 
android:textColor="?attr/myTextViewColor" 
[...] /> 
+1

谢谢,但attr解决方案没有工作,我得到以下内容:错误膨胀类 jjdev80