angular - 如何更改 Angular Material 步进器步骤图标的颜色

标签 angular angular-material material-design

在 Angular Material 步进器组件中,每个步骤都由圆圈中的图标表示。该圆圈的背景颜色设置为主题的主要颜色。是否可以将此颜色更改为主题的强调色?我试过设置 color="accent"mat-horizontal-stepper 上组件和每个 mat-step组件,但两者都没有任何效果,而且我在文档中没有看到颜色输入。

最佳答案

似乎没有更改垫子步进器图标颜色的选项,您可以使用此 css 作为解决方法。

 ::ng-deep .mat-step-header .mat-step-icon-selected {
    background-color: red; 
 }

::ng-深已弃用,可以删除,也可以使用

ViewEncapsulation.None 在组件装饰器中避免使用::ng-deep

更新问题的解决方案

html文件示例
 <div class="yellow-theme"> <----- wrapper theme class
     <button mat-raised-button (click)="isLinear = !isLinear" id="toggle- 
      linear">
            {{!isLinear ? 'Enable linear mode' : 'Disable linear mode'}}
          </button>
          <mat-horizontal-stepper [linear]="isLinear" #stepper>
            <mat-step [stepControl]="firstFormGroup">
              <form [formGroup]="firstFormGroup">
                <ng-template matStepLabel>Fill out your name</ng-template>
                <mat-form-field>
                  <input matInput placeholder="Last name, First name" 
                  formControlName="firstCtrl" required>
                </mat-form-field>
                <div>
                  <button mat-button matStepperNext>Next</button>
                </div>
              </form>
            </mat-step>
            <mat-step [stepControl]="secondFormGroup">
              <form [formGroup]="secondFormGroup">
                <ng-template matStepLabel>Fill out your address</ng-template>
                <mat-form-field>
                  <input matInput placeholder="Address" formControlName="secondCtrl" required>
                </mat-form-field>
                <div>
                  <button mat-button matStepperPrevious>Back</button>
                  <button mat-button matStepperNext>Next</button>
                </div>
              </form>
            </mat-step>
            <mat-step>
              <ng-template matStepLabel>Done</ng-template>
              You are now done.
              <div>
                <button mat-button matStepperPrevious>Back</button>
                <button mat-button (click)="stepper.reset()">Reset</button>
              </div>
            </mat-step>
          </mat-horizontal-stepper>

创建 theme.scss 文件并将其添加到 angular.json 中的样式
 "styles": [
          "src/styles.css",
          "src/theme.scss"
           ]

备注 步进器将采用原色的颜色

主题.scss
 @import '~@angular/material/theming';
 @include mat-core();

 .yellow-theme {
     $yellow-theme-primary: mat-palette($mat-yellow, 400);
     $yellow-theme-accent:  mat-palette($mat-yellow, 400);

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

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

自定义主题类可以跨应用程序使用,只需包装任何 Material 组件并使用类中定义的颜色属性primary、accent 或warn。
包装在自定义类中的组件将使用该颜色,如果不是从全局主题设置颜色。

关于angular - 如何更改 Angular Material 步进器步骤图标的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53213544/

相关文章:

html - 如何使用 Tab 键使 Toggle 按钮可聚焦

angular - 将 .Net Core Angular 6 发布到 Azure 时出错

android - 操作栏后退箭头方向

angular - 将对象属性绑定(bind)到输入并将值传递给按钮单击 Angular 函数

angular - 使用 Angular Material 核心主题的 Angular 应用程序中的字体在哪里加载?

javascript - 如何使用 Angular Material 对多个复选框进行分组

Angular 响应式(Reactive)验证

android - 安卓:elevation tag raises issue in android layout file

Android appcompat-v7 :21. 0.0 更改 Material 复选框颜色

angular - 如何在 Angular 7 中使用管道强制执行 http 请求中的顺序