经过一番研究,我最终得出了这个结论,它为我解决了这个问题,希望它也能帮助你。
第 1 步:使用品牌颜色创建您自己的调色板。
找到了这个很棒的网站,您可以在其中输入您的品牌颜色,它会创建一个包含该品牌颜色不同色调的完整调色板:http://mcg.mbitson.com
我将这个工具用于我的primary 颜色(这是我的品牌颜色)和accent 颜色。
第 2 步:在自定义主题文件中创建调色板
这里是如何创建这样的.scss 文件的指南:https://github.com/angular/material2/blob/master/guides/theming.md
@import '~@angular/material/theming';
// Be sure that you only ever include 'mat-core' mixin once!
// it should not be included for each theme.
@include mat-core();
// define a real custom palette (using http://mcg.mbitson.com)
$bv-brand: (
50: #ffffff,
100: #dde6f3,
200: #b4c9e4,
300: #7fa3d1,
400: #6992c9,
500: #5282c1,
600: #4072b4,
700: #38649d,
800: #305687,
900: #284770,
A100: #ffffff,
A200: #dde6f3,
A400: #6992c9,
A700: #38649d,
contrast: (
50: $black-87-opacity,
100: $black-87-opacity,
200: $black-87-opacity,
300: $black-87-opacity,
400: $black-87-opacity,
500: white,
600: white,
700: white,
800: white,
900: white,
A100: $black-87-opacity,
A200: $black-87-opacity,
A400: $black-87-opacity,
A700: white,
)
);
$bv-orange: (
50: #ffffff,
100: #fff7f4,
200: #fecdbd,
300: #fc9977,
400: #fc8259,
500: #fb6c3b,
600: #fa551d,
700: #f44205,
800: #d63a04,
900: #b83204,
A100: #ffffff,
A200: #fff7f4,
A400: #fc8259,
A700: #f44205,
contrast: (
50: $black-87-opacity,
100: $black-87-opacity,
200: $black-87-opacity,
300: $black-87-opacity,
400: $black-87-opacity,
500: white,
600: white,
700: white,
800: white,
900: white,
A100: $black-87-opacity,
A200: $black-87-opacity,
A400: $black-87-opacity,
A700: white,
)
);
// mandatory stuff for theming
$bv-palette-primary: mat-palette($bv-brand);
$bv-palette-accent: mat-palette($bv-orange);
// include the custom theme components into a theme object
$bv-theme: mat-light-theme($bv-palette-primary, $bv-palette-accent);
// include the custom theme object into the angular material theme
@include angular-material-theme($bv-theme);
上面代码的一些解释
左侧的数字设置亮度的“级别”。默认值为 500(这是我的品牌颜色/强调色的真实阴影)。所以在这个例子中,我的品牌颜色是#5282c1。其余的是该颜色的其他色调(数字越小表示色调越亮,数字越大表示色调越暗)。 AXXX 是不同的色调。 (还)不确定它们在哪里使用。同样,较低的数字意味着更亮,更高的数字意味着更暗。
contrast 将字体颜色设置为这些背景颜色。很难(甚至不可能)通过 CSS 计算字体应该是亮(白色)还是暗(黑色,不透明度为 0.87),因此即使是色盲的人也很容易阅读。所以这是手动设置并硬编码到调色板定义中。你也可以从我上面链接的调色板生成器中得到这个(虽然它是以旧的 Material1 格式输出的,你必须像我在这里发布的那样手动将它转换为 Material2 格式)。
将主题设置为使用品牌调色板作为primary 颜色,并将任何你有强调的颜色作为你的accent 颜色。
第 3 步:尽可能在整个应用中使用主题
部分元素可以采用主题色,如<md-toolbar>、<md-input>、<md-button>、<md-select>等。他们将默认使用primary,因此请确保将品牌调色板设置为主要颜色。如果要更改颜色,请使用 color 指令(它是 Angular 指令吗?)。
例如:
<button mat-raised-button color="accent" type="submit">Login</button>