Android 更改主题时仅更改颜色
我想在我的android应用程序中支持不同的主题。 主题应该只有两种颜色不同。因此,每个主题都有以下颜色:Android 更改主题时仅更改颜色,android,android-resources,android-theme,android-styles,android-color,Android,Android Resources,Android Theme,Android Styles,Android Color,我想在我的android应用程序中支持不同的主题。 主题应该只有两种颜色不同。因此,每个主题都有以下颜色: 原色 次要颜色 我想要的是,有一个大的默认主题,也有像按钮样式et这样的子主题,比如(styles.xml): 现在我可以在我的style.xml中使用这个属性,如下所示: <style name="DefaultTheme.Button"> <item name="android:textAllCaps">true</item> &
- 原色
- 次要颜色
style.xml
中使用这个属性,如下所示:
<style name="DefaultTheme.Button">
<item name="android:textAllCaps">true</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">?attr/ThemeColorPrimary</item>
[...]
</style>
<item name="ThemeColorPrimary">@color/ThemeBluePrimary</item>
<activity
android:name="StackOverflowActivity"
android:screenOrientation="portrait"
android:theme="@style/DefaultTheme.NoActionBar" />
因为指定的资源将丢失。否则我也无法做到这一点:
<activity
android:name="StackOverflowActivity"
android:screenOrientation="portrait"
android:theme="@style/BlueTheme.NoActionBar" />
因为BlueTheme没有称为“NoActionBar”的子级
我知道这让人困惑,我自己也很困惑。
我怎样才能解决这个问题?
提前感谢。您必须在父主题中指定这些自定义属性:
<style name="DefaultTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="ThemeColorPrimary">@color/defaultPrimaryColor</item>
<item name="ThemeColorSecondary">@color/defaultSecondaryColor</item>
</style>
<activity
android:name="StackOverflowActivity"
android:screenOrientation="portrait"
android:theme="@style/DefaultTheme.NoActionBar" />
<activity
android:name="StackOverflowActivity"
android:screenOrientation="portrait"
android:theme="@style/BlueTheme.NoActionBar" />
<style name="DefaultTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="ThemeColorPrimary">@color/defaultPrimaryColor</item>
<item name="ThemeColorSecondary">@color/defaultSecondaryColor</item>
</style>
<style name="BlueNoActionBarTheme" parent="DefaultTheme.NoActionBar">
<item name="ThemeColorPrimary">@color/ThemeBluePrimary</item>
<item name="ThemeColorSecondary">@color/ThemeBlueSecondary</item>
</style>