Theming in Angular 6 (and 7) for Mat-button-toggle

穿精又带淫゛_ 提交于 2019-12-11 13:01:32

问题


I found the wonderful link how to customize the Material toggle button. I succeed to set the background-color and the font-weight the way I want with

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

@include mat-core();

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

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

@mixin mix-app-theme($app-theme) {
  $primary: map-get($app-theme, primary);
  $accent: map-get($app-theme, accent);

.mat-button-toggle-checked {
    background-color: mat-color($primary);
    font-weight: bold;
    color:mat-color($primary); // <=== does not work!!!
  }
}

// Include the mixin
@include mix-app-theme($app-theme);

But somehow the font itself remains on black - which is not the default color when using color="primary".

Any idea how to include the fore-color as well - properly?


回答1:


try using this

.mat-button-toggle-label-content{
   color:mat-color($primary)
}

if you want change color of checked button only try this

.mat-button-toggle-checked {
   .mat-button-toggle-label-content{
       color:mat-color($primary)
    }
}



回答2:


Thanx to @Akhi Akl I and looking into the themes I found the following solution for mat-button-toggle in color primary

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

@include mat-core();

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

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

@mixin mix-app-theme($app-theme) {
  $primary: map-get($app-theme, primary);

  .mat-button-toggle-checked {
    background-color: mat-color($primary);
    font-weight: bold;

    .mat-button-toggle-label-content{
        color: $light-primary-text;
    }
  }
}

// Include the mixin
@include mix-app-theme($app-theme);


来源:https://stackoverflow.com/questions/53836382/theming-in-angular-6-and-7-for-mat-button-toggle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!