Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing Primary Color in Angular Material 2

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)

like image 885
duke636 Avatar asked Aug 03 '16 04:08

duke636


People also ask

How do I change the theme of angular materials?

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.

How do I overwrite angular materials in css?

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.

What is theming in angular?

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.

How do I create a custom material theme?

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!

How color work in Angular Material?

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.

What are themes in Angular Material?

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.

How to add material design in angular?

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.

Where can I find styles for color and typography in angular?

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:


1 Answers

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

like image 144
Daniel Hoppe Alvarez Avatar answered Oct 29 '22 23:10

Daniel Hoppe Alvarez