使用Angular Material的主题变量,实现自定义主题样式。
Angular Material提供了一系列的全局CSS变量来控制组件的样式,可以通过修改这些变量值来实现自定义的主题样式。具体实现步骤如下:
@use '~@angular/material' as mat;
// 定义自定义主题样式 $custom-theme: mat.define-light-theme(( color: ( primary: #009688, accent: #ff6f00, warn: #f44336, ), ));
// 将自定义样式合并到默认主题中 $theme: mat.all-component-themes(mat.get-light-theme(), $custom-theme);
// 应用主题样式 @include mat.apply-light-theme($theme);
代码示例:
styles.scss
@use '~@angular/material' as mat;
// 定义自定义主题样式
$custom-theme: mat.define-light-theme((
color: (
primary: #009688,
accent: #ff6f00,
warn: #f44336,
),
));
// 将自定义样式合并到默认主题中
$theme: mat.all-component-themes(mat.get-light-theme(), $custom-theme);
// 应用主题样式
@include mat.apply-light-theme($theme);