棱角材质更改默认字体颜色

时间:2018-12-09 05:18:52

标签: css angular angular-material angular-material-theming

我使用的是棱角分明的材料,在主题化时有点迷失了。我正在使用下面的styles.scss中包含的预构建的靛蓝粉红色主题

@import "~@angular/material/prebuilt-themes/indigo-pink.css"; 

基于该文档,我创建了一个名为theme.scss的新文件,并将其包含在styles.scss之后的angular.json中。 theme.scss如下所示

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

@include mat-core();

$sg-app-primary: mat-palette($mat-indigo);
$sg-app-accent:  mat-palette($mat-pink, A200, A100, A400);

$sg-app-theme: mat-light-theme($sg-app-primary, $sg-app-accent);

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

我的要求 我只需要在各处将默认字体颜色更改为白色而不是黑色即可。我根本不需要更改任何其他内容。我只是从示例中复制了主要和重音调色板。因此即使不需要更改它们的感觉。

2 个答案:

答案 0 :(得分:2)

我相信这篇文章会回答您的问题:https://stackoverflow.com/a/46157803/10730815。基本上,您需要构建一个自定义前景地图并将其合并到您的主题中。将您的代码段与上面的文章中的代码段结合起来,就可以为您的styles.scss提供类似的内容:

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

@include mat-core();

$sg-app-primary: mat-palette($mat-indigo);
$sg-app-accent:  mat-palette($mat-pink, A200, A100, A400);

$sg-app-theme: mat-light-theme($sg-app-primary, $sg-app-accent);

@function my-mat-light-theme-foreground($color) {
    @return (
        base:              $color,
        divider:           $white-12-opacity,
        dividers:          $white-12-opacity,
        disabled:          rgba($color, 0.38),
        disabled-button:   rgba($color, 0.38),
        disabled-text:     rgba($color, 0.38),
        hint-text:         rgba($color, 0.38),
        secondary-text:    rgba($color, 0.54),
        icon:              rgba($color, 0.54),
        icons:             rgba($color, 0.54),
        text:              rgba($color, 0.87),
        slider-off:        rgba($color, 0.26),
        slider-off-active: rgba($color, 0.38),
        slider-min:        rgba($color, 0.38)
    );
};

$white-foreground: my-mat-light-theme-foreground(white);
$my-app-theme-custom: map-merge($sg-app-theme, (foreground: $white-foreground));

@include angular-material-theme($my-app-theme-custom);

/* For the non-Angular Material items */
body {
    color: white;
}

答案 1 :(得分:0)

在一些实用函数中,您可以只传入几个必要的调色板,例如主要、重音和警告,它会为您包含背景和前景色。

这些功能也可以在angular material文件提供的scss中找到,如果导入的话,可以在创建主题配置时使用。

此处提供参考,以便您了解它们如何自动包含浅色和深色主题的前景和背景。他们的作品真棒。

 @function _mat-create-light-color-config($primary, $accent, $warn: null) {
  @return (
    primary: $primary,
    accent: $accent,
    warn: if($warn != null, $warn, mat-palette($mat-red)),
    is-dark: false,
    foreground: $mat-light-theme-foreground,
    background: $mat-light-theme-background,
  );
}


@function _mat-create-dark-color-config($primary, $accent, $warn: null) {
  @return (
    primary: $primary,
    accent: $accent,
    warn: if($warn != null, $warn, mat-palette($mat-red)),
    is-dark: true,
    foreground: $mat-dark-theme-foreground,
    background: $mat-dark-theme-background,
  );
}
相关问题