角材料更改默认字体颜色

Mob*_* IT 8 css angular-material angular angular-material-theming

我正在使用有角度的材料,但在主题化方面有点迷失。我正在使用我的styles.scss 中包含的预构建的靛蓝色粉红色主题,如下所示

@import "~@angular/material/prebuilt-themes/indigo-pink.css"; 
Run Code Online (Sandbox Code Playgroud)

根据文档,我创建了一个名为 theme.scss 的新文件,并将其包含在 angular.json 之后的 style.scss 中。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);
Run Code Online (Sandbox Code Playgroud)

我的要求 我只需要在所有地方将默认字体颜色更改为白色而不是黑色。我根本不需要改变任何其他东西。我只是从示例中复制了主要和重音调色板。所以感觉即使他们不需要改变。

cod*_*iet 10

我相信这篇文章回答了你的问题: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;
}
Run Code Online (Sandbox Code Playgroud)