Angular 2 Material 前景

Angular 2 Material Foreground

我在 angular 2 material 中更改前景颜色有困难。例如在工具栏中,文本是黑色的。我尝试用以下样式更改它

@import '~@angular/material/theming';

$primary: mat-palette($mat-cyan, 300);
$accent : mat-palette($mat-yellow, 500);;
$warn : mat-palette($mat-red, 600);

$theme-foreground: (
  base:              gray,
  divider:           $white-12-opacity,
  dividers:          $white-12-opacity,
  disabled:          rgba(200, 200, 200, 0.38),
  disabled-button:   rgba(200, 200, 200, 0.38),
  disabled-text:     rgba(200, 200, 200, 0.38),
  hint-text:         rgba(200, 200, 200, 0.38),
  secondary-text:    rgba(200, 200, 200, 0.54),
  icon:              rgba(200, 200, 200, 0.54),
  icons:             rgba(200, 200 , 200, 0.54),
  text:              rgba(200, 200, 200, 0.87),
  slider-min:        rgba(200, 200, 200, 0.87),
  slider-off:        rgba(200, 200, 200, 0.26),
  slider-off-active: rgba(200, 200, 200, 0.38),
);

$theme-background: (
  status-bar: map_get($mat-grey, 300),
  app-bar:    map_get($mat-grey, 100),
  background: map_get($mat-grey, 50),
  hover:      rgba(200, 200, 200, 0.04), // TODO(kara): check style with Material Design UX
  card:       white,
  dialog:     white,
  disabled-button: $black-12-opacity,
  raised-button: white,
  focused-button: $black-6-opacity,
  selected-button: map_get($mat-grey, 300),
  selected-disabled-button: map_get($mat-grey, 400),
  disabled-button-toggle: map_get($mat-grey, 200),
  unselected-chip: map_get($mat-grey, 300),
);

$theme: (
    primary: $primary,
    accent: $accent,
    warn: $warn,
    is-dark: true,
    foreground: $theme-foreground,
    background: $theme-background
  );

@include mat-core();

@include angular-material-theme($theme);

主色和强调色已更改,但前端未更改。 我该如何解决?

我也试过设置工具栏主题,但没有任何区别。

尝试定义您自己的主题,您还可以在此处定义前景色:

由于投票不足而更新,这可能来自不了解 material 设计如何运作的人:

如果您不知道 Material 设计是如何工作的,请先阅读优秀指南 https://tomastrajan.medium.com/the-complete-guide-to-angular-material-themes-4d165a9d24d1 and check the official documentation at https://material.io/design/material-theming/overview.html#material-theming

关于这个post的评论,Material设计不知道前景色。我理解人们的意思是“前景”颜色,即字体的颜色。没有一种这样的颜色,有多种颜色。您需要在 Angular 如何设置字体颜色中了解更多关于主题的信息。下面我简单说明一下。

Material 设计使用原色、强调色和警告色,每个组件使用不同的颜色。

您使用 mat-palette 定义主色、重音色和警告色,它采用 处接受的答案中显示的样式作为第一个参数。 Material Design 为每种颜色使用默认的、较浅和较深的变体,默认情况下是为键 500、100 和 700 定义的颜色。您可以通过向 mat-palette 提供更多参数来更改变体。

在每种颜色(primary, accent and warn)的主题定义中,都有一个contrast entry。在对比度条目下,您可以找到与为主题定义的颜色变量相对应的字体颜色。

Whosebug post 我指的是深入解释

The contrast sets the font color over those background colors.

别人已经解释的很好了,我就不用再解释了。我最好只 link 进行解释。然而,我无法控制我被否决,因为 Material 设计不知道“前景”颜色的概念,而是使用不同的术语。

您设置自定义前景和背景的方式是正确的 - 但是,工具栏的字体颜色决定如下:

  • 如果工具栏设置为 primary/accent/warn 颜色,则使用默认对比色
  • 否则使用前景文本颜色

换句话说,如果您的工具栏颜色使用主调色板,您将不得不尝试使用 $primary 的对比色 - 不推荐这种颜色,因为 material组件使用这些。最好采用老式的方式,手动更改工具栏颜色。

如果您真的下定决心,可以使用所需的对比色制作自定义 primary/accent 调色板,然后使用它来创建主题,如下所示: https://github.com/angular/material2/blob/master/src/lib/core/theming/_palette.scss

我建议坚持使用灰度颜色来形成对比 - 在某些情况下 Material 会采用一种颜色并将其反转,因此您最终可能会得到一些古怪的东西。