Angular theme with more than 3 colors

后端 未结 3 1376
一整个雨季
一整个雨季 2020-12-19 21:46

I want to make an angular theme with more than three colors (primary, accent, warn) and apply those colors to material elements like progress bars and such.

I was re

相关标签:
3条回答
  • 2020-12-19 22:14

    Up to Angular Material 6.x (I don't know what 7.x etc. might change), only the three primary/accent/warn palettes are available within a theme. This is very limiting, but there is one thing you can do that might be useful sometimes - define more than one theme.

    Extra themes give you extra primary, accent, and warn palettes. You can then apply different themes to different components depending on which primary, accent, and warn colors you want each component to have. (You may need to dig in to Angular Material source code to figure out how to do this, but it's not that complicated - just look at what the angular-material-theme mixin does.)

    Obviously, this doesn't give you more color options per component, but it does let you use more colors in your application and use alternate colors for selected components. This is sort of against the idea of theming in Material Design, so use cautiously.

    For example:

    @import '~@angular/material/theming';
    
    $main-theme: mat-light-theme($mat-purple, $mat-yellow, $mat-red);
    $alternate-theme: mat-light-theme($mat-deep-purple, $mat-amber, $mat-red);
    
    @include mat-core-theme($main-theme);
    @include mat-autocomplete-theme($main-theme);
    @include mat-badge-theme($alternate-theme);
    ...
    
    0 讨论(0)
  • 2020-12-19 22:21

    You can define an alternate theme through this link:

    https://alligator.io/angular/angular-material-custom-theme/

    Then you can use more than three themes ;)

    0 讨论(0)
  • 2020-12-19 22:33

    As of Angular Material 9, you are still limited to 3 colors still. You can achieve more than 3 colors by using multiple themes.

    You can generate a color palette using the following generator:

    http://mcg.mbitson.com/#!?mcgpalette0=%233f51b5

    You'll need a palette per color you want to add.

    Then you can create multiple themes to use at once by following their documentation on adding multiple themes:

    https://material.angular.io/guide/theming#multiple-themes

    0 讨论(0)
提交回复
热议问题