【问题标题】:How to set color variants for dark mode?如何为暗模式设置颜色变体?
【发布时间】:2019-10-18 09:10:11
【问题描述】:

我需要为明暗模式调色板设计应用程序。应用程序使用 10 种不同的颜色作为背景/按钮/文本。我想要实现的是在styles.xml 中为暗模式设置theme,并为来自相反色谱的大多数颜色设置darkMode 变体。对于文本/操作栏,我有不同深浅的白色和灰色。问题是我只能在我的主题中设置 2 种原色,colorPrimarycolorPrimaryDark。这些颜色我从未在我的应用程序中使用过,因为我有完全自定义的布局,每个 xml 都有自定义颜色。

有什么方法可以实现吗?

【问题讨论】:

标签: android android-layout android-theme android-color


【解决方案1】:

您可以在 values.xml 中更改这些颜色。你也可以在那里声明你的应用程序的颜色,这样你就不必为每个 xml 自定义所有东西,你只需要添加你之前声明的颜色的名称。

例子:

Colors.xml

<color name="red">#f80404</color>

在你看来

<TextView
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:textColor="@color/red"/>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-24
    • 1970-01-01
    • 2021-09-13
    • 2015-03-14
    • 1970-01-01
    • 2011-09-10
    相关资源
    最近更新 更多