I am trying to change the default primary color in Angular Material 2 (alpha 6).
I got some idea from this official doc.
I located _default-theme.scss
from node_modules > @angular2-material > core > style
and replaced the color teal by purple in the following line.
$md-primary: md-palette($md-teal, 500, 100, 700, $md-contrast-palettes);
But the color teal is still shown in the page and pink never appears. What am I missing? How can I change the primary color?
(I am using Angular Material 2 alpha 6 with Angular 2 RC4)
add("custom-theme"); With adding class="mat-app-background" to the <body> tag, the correct background color will take effect. As you call @include angular-material-theme($custom-theme); within your custom custom-them-css-class mixin, the mat-app-background css-selector will become a nested selector.
Our solution to ViewEncapsulation was to override very specific css using highly specific css selectors in 1) global css or 2) creating separate style files for certain views / styles / elements, importing into every component required (e.g. styleUrls: [material-table-override.
Angular Material's theming system lets you customize color and typography styles for components in your application. The theming system is based on Google's Material Design specification. This document describes the concepts and APIs for customizing colors. For typography customization, see Angular Material Typography.
To do so open the Settings and navigate to Appearance & Behavior → Material Theme UI → Custom Theme. Once you're done customizing your colors, you'll need to select Custom Theme or Light Custom Theme from the Theme Switcher to see your colors in action. Enjoy!
Angular material color | Learn How Color work in Angular material? By using Angular material we can modify the color of component and choose the color we want, for this material provide us themes by which we can style our components this make use of google material design.
In Angular Material, a theme is a collection of color and typography options. Each theme includes three palettes that determine component colors: primary, accent and warn. Angular Material's theming system comes with a predefined set of rules for color and typography styles. The theming system is based on Google's Material Design specification.
Since Angular gives you a choice to apply styles of your own choice, the material design needs to be explicitly added to the project. But don’t worry, the task is pretty simple. Go to the root directory of your project and execute following command Once the installation is complete, make sure that you import BrowserAnimationsModule in main module.
Angular Material offers a "theme" mixin that emits styles for both color and typography and It’s the all-component-themes mixin. You can check the source file: src/material/core/theming/_all-theme.scss to see the mixin all-component-themes:
Angular 4+ and Angular Material 2.0.0 beta 10, Angular CLI 1.3+
You will have to create a scss file "exampleTheme.scss" , you add it to your angular-cli.json angular-cli.json:
"styles": [
//if you are using --scss the file is called style.scss
"styles.css",
"customTheme.scss"
],
In your customTheme.scss you can change your colors in use of the following code:
@import '~@angular/material/theming';
@include mat-core();
$primary: mat-palette($mat-blue,200);
$accent: mat-palette($mat-orange,200);
$theme: mat-light-theme($primary, $accent);
@include angular-material-theme($theme);`
Multiple Themes If you want to have an additional theme please read the guide linked in the end. But here a small overview you just have to replicate the theming process with new variables and colors
$dark-primary: mat-palette($mat-blue,800);
$dark-accent: mat-palette($mat-orange,800);
$dark-theme: mat-dark-theme($primary, $accent);
and add
.material-dark-theme {
@include angular-material-theme($dark-theme);
}
for more detailed information you should read the angular material theme guide
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With