gpt4 book ai didi

android - 在一个主题中组合颜色

转载 作者:行者123 更新时间:2023-11-29 22:43:59 27 4
gpt4 key购买 nike

我想创建主题父 Theme.MaterialComponents.DayNight.NoActionBarTheme.MaterialComponents.DayNight。但我不想复制其中的颜色,比如

<resources>

<style name="AppTheme.Base" parent="Theme.MaterialComponents.DayNight">

<item name="colorPrimary">@color/color_primary</item>
<item name="colorPrimaryVariant">@color/color_primary_variant</item>
<item name="colorSecondary">@color/color_secondary</item>
<item name="colorSecondaryVariant">@color/color_secondary_variant</item>

<item name="android:colorBackground">@color/color_background</item>
<item name="colorSurface">@color/color_surface</item>
<item name="colorError">@color/color_error</item>

<item name="colorOnPrimary">@color/color_on_primary</item>
<item name="colorOnSecondary">@color/color_on_secondary</item>
<item name="colorOnBackground">@color/color_on_background</item>
<item name="colorOnSurface">@color/color_on_surface</item>
<item name="colorOnError">@color/color_on_error</item>
</style>

<style name="AppTheme.Base.NoActionBar" parent="Theme.MaterialComponents.DayNight.NoActionBar">

<item name="colorPrimary">@color/color_primary</item>
<item name="colorPrimaryVariant">@color/color_primary_variant</item>
<item name="colorSecondary">@color/color_secondary</item>
<item name="colorSecondaryVariant">@color/color_secondary_variant</item>

<item name="android:colorBackground">@color/color_background</item>
<item name="colorSurface">@color/color_surface</item>
<item name="colorError">@color/color_error</item>

<item name="colorOnPrimary">@color/color_on_primary</item>
<item name="colorOnSecondary">@color/color_on_secondary</item>
<item name="colorOnBackground">@color/color_on_background</item>
<item name="colorOnSurface">@color/color_on_surface</item>
<item name="colorOnError">@color/color_on_error</item>
</style>

我可以将颜色组合成一个主题并在 2 个主题中继承吗?

最佳答案

只需使用:

<style name="AppTheme.Base" parent="Theme.MaterialComponents.DayNight">
<!-- add the colors -->
</style>


<style name="AppTheme.Base.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>

这样,AppTheme.Base.NoActionBar 样式继承了上面AppTheme.Base 样式的所有样式,并添加了 windowActionBar windowNoTitle 属性。

同时检查 official documentation :

Note: If you use the dot notation to extend a style, and you also include the parent attribute, then the parent styles override any styles inheritted through the dot notation.

关于android - 在一个主题中组合颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58731566/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com