Android 如何将主题资源应用于多个主题?
如果应用程序中使用了单亲主题,则用户可选择的主题(亮和暗),每个主题都有自己的资源:Android 如何将主题资源应用于多个主题?,android,android-theme,android-styles,Android,Android Theme,Android Styles,如果应用程序中使用了单亲主题,则用户可选择的主题(亮和暗),每个主题都有自己的资源: <style name="MyApp.Dark" parent="android:Theme.Material"> <item name="themeBackground">@color/dark_grey</item> <item name="themeBackgroundTransparent">@color/darkColorBackgrou
<style name="MyApp.Dark" parent="android:Theme.Material">
<item name="themeBackground">@color/dark_grey</item>
<item name="themeBackgroundTransparent">@color/darkColorBackgroundTransparent</item>
<item name="colorPrimary">@color/darkColorPrimary</item>
.
.
</style>
<style name="MyApp.Light" parent="android:Theme.Material.Light">
<item name="themeBackground">@color/brown_50</item>
<item name="themeBackgroundTransparent">@color/lightColorBackgroundTransparent</item>
<item name="colorPrimary">@color/lightColorPrimary</item>
.
.
</style>
为了将主题化资源应用于新主题,一个简单的解决方案是将MyApp.Dark
主题中的单个项目复制并粘贴到新的MyApp.DialogWhenLarge.Dark
主题中,等等,但是重复代码的数量变得难以管理、无法理解,而且随着主题和资源数量的增加,容易出错
所以我的问题是,将主题资源应用于多个主题定义的简单方法是什么?
理想情况下,可以将一组资源应用于主题,就像将样式应用于视图一样,这将导致以下形式的解决方案:
<style name="MyApp.DialogWhenLarge.Light" parent="android:Theme.Material.Light.DialogWhenLarge">
<item name="themedResources">[pointer to canonical list of light theme resources]
</style>
[指向灯光主题资源规范列表的指针]
当然,同样重要的是,任何解决方案都保留从视图中引用主题资源的能力,其格式为?themeBackground
<style name="MyApp.DialogWhenLarge.Light" parent="android:Theme.Material.Light.DialogWhenLarge">
<item name="themedResources">[pointer to canonical list of light theme resources]
</style>