android风格的继承

android风格的继承,android,android-layout,android-styles,Android,Android Layout,Android Styles,我已经为TextView定义了红色到contentBg样式。我可以通过从父样式更改或重命名样式名称myContentNew将TextView颜色从红色更改为蓝色吗?不应更改TextView样式名称contentBG。在安卓系统中可能吗 <RelativeLayout style="@style/myContent" android:layout_width="fill_parent" android:layout_height="wrap_content"> &l

我已经为TextView定义了红色到contentBg样式。我可以通过从父样式更改或重命名样式名称myContentNew将TextView颜色从红色更改为蓝色吗?不应更改TextView样式名称contentBG。在安卓系统中可能吗

<RelativeLayout 
   style="@style/myContent"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content">
<TextView 
   style="@style/contentBG"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"/>
</RelativeLayout>
谢谢,恐怕不行


设置
contentBG
样式后。它只能在代码中更改。

以下是创建两个不同主题的示例:

您需要首先修改清单文件以调用默认自定义主题,例如:

<application
    android:name="RateDayApplication"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/CustomTheme" >
重要提示:这里我使用
Theme.Holo.Light
作为父主题,如果使用不同的主题,可以对其进行更改

在上面的两个主题中,样式具有相同的名称,它将用作XML文件中的引用。要声明此引用,必须将其添加到
values
文件夹下的文件untitled
attrs.xml

内容如下:

<?xml version="1.0" encoding="utf-8"?>
<resources>
   <attr name="contentBG" format="reference" />
</resources>


你好像在试着设置一个主题,对吗?您需要在一个布局或所有布局中执行此操作吗?实际上,我想根据上述要求将其用作活动或非活动状态。我认为您不能直接设置此类继承。我看到的唯一方法是设置2个主题,并使用样式作为参考,这些样式将根据所选主题的不同而变化。您能告诉我如何做到这一点吗?我添加了一个答案,希望答案足够清楚!
<application
    android:name="RateDayApplication"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/CustomTheme" >
<!-- *** THEME WITH RED BG*** -->
<style name="CustomTheme" parent="@android:style/Theme.Holo.Light">
    <item name="contentBG">@style/contentBGred</item>

</style>

<style name="contentBGred" >
    <item name="android:colorBackground">@color/red</item>
</style>

<!-- *** THEME WITH BLUE BG*** -->
<style name="CustomThemeNew" parent="@android:style/Theme.Holo.Light">
    <item name="contentBG">@style/contentBGblue</item>
</style>

<style name="contentBGblue" >
    <item name="android:colorBackground">@color/blue</item>
</style>
<?xml version="1.0" encoding="utf-8"?>
<resources>
   <attr name="contentBG" format="reference" />
</resources>
<RelativeLayout 
   android:layout_width="fill_parent"
   android:layout_height="wrap_content">
<TextView 
   style="?contentBG"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"/>
</RelativeLayout>
setTheme(R.style.CustomTheme);
setTheme(R.style.CustomThemeNew);