Angular Material - Angular Material Theme - Angular Material Tutorial



How to Create Theme in Angular Material?

  • A theme is a composition of color palettes. That’s right, not just a single color palette, multiple color palettes.
  • This is a very powerful setup to define themes in a very flexible way.
  • learn angular material tutorials - themes

    learn angular material tutorials - themes Example

  • As for Angular Material, it boils down to five different color palettes with each being used for different parts of the design:
  • Primary - Main colors most widely used across all screens and components.
  • Accent - Also known as the secondary color. Used for floating action buttons and interactive elements.
  • Warn - Colors to convey error state.
  • Foreground - Used for text and icons.
  • Background - Colors used for element backgrounds.
Related Tags - angular material , angular 2 material , angular material 2 , angular material design , material angular

Using a pre-built theme:

  • Angular Material comes prepackaged with several pre-built theme css files. These theme files also include all of the styles for core (styles common to all components), so you only have to include a single css file for Angular Material in your app.
  • You can include a theme file directly into your application from @angular/material/prebuilt-themes

Available pre-built themes:

  • deeppurple-amber.css
  • indigo-pink.css
  • pink-bluegrey.css
  • purple-green.css
  • If you're using Angular CLI, this is as simple as including one line in your styles.css file:
@import '~@angular/material/prebuilt-themes/deeppurple-amber.css';
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy angular material tutorial , angular 4 material , angular material2 , angular material example team
  • Alternatively, you can just reference the file directly. This would look something like:
<link href="node_modules/@angular/material/prebuilt-themes/indigo-pink.css" rel="stylesheet">
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy angular material tutorial , angular 4 material , angular material2 , angular material example team
  • The actual path will depend on your server setup.
  • You can also concatenate the file with the rest of your application's css.
  • Finally, if your app's content is not placed inside of a md-sidenav-container element, you need to add the mat-app-background class to your wrapper element (for example the body).
  • This ensures that the proper theme background is applied to your page.
  • Angular Material Components uses intention group classes like md-primary, md-accent, md-warn and additional classes for color differences like md-hue-1, md-hue-2, or md-hue-3.

Following components supports use of above mentioned classes:

  • md-button
  • md-checkbox
  • md-progress-circular
  • md-progress-linear
  • md-radio-button
  • md-slider
  • md-switch
  • md-tabs
  • md-text-float
  • md-toolbar

Using a pre-built theme: Example:

  • The following example showcases the use of themes in Angular JS application.
<html lang="en" >
   <head>
      <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/angular_material/1.0.0/angular-material.min.css">
      <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
      <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-animate.min.js"></script>
      <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-aria.min.js"></script>
      <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-messages.min.js"></script>
      <script src="https://ajax.googleapis.com/ajax/libs/angular_material/1.0.0/angular-material.min.js"></script>
      <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
      <script language="javascript">
         angular
            .module('firstApplication', ['ngMaterial'])
            .controller('themeController', themeController)
            .config(function($mdThemingProvider) {
               $mdThemingProvider.theme('customTheme') 
                  .primaryPalette('grey')
                  .accentPalette('orange')
                  .warnPalette('red');
               });

            function themeController ($scope) {            
            }	  
      </script>      
   </head>
   <body ng-app="firstApplication"> 
      <div id="themeContainer" ng-controller="themeController as ctrl" ng-cloak>
         <md-toolbar class="md-primary"><div class="md-toolbar-tools"><h2 class="md-flex">Default Theme</h2></div></md-toolbar>
      <hr/>
      <md-card>         
         <md-card-content layout="column"> 
            <md-toolbar class="md-primary"><div class="md-toolbar-tools"><h2 class="md-flex">Using md-primary style</h2></div></md-toolbar>
            <md-toolbar class="md-primary md-hue-1"><div class="md-toolbar-tools"><h2 class="md-flex">Using md-primary md-hue-1 style</h2></div>
</md-toolbar>
            <md-toolbar class="md-primary md-hue-2"><div class="md-toolbar-tools"><h2 class="md-flex">Using md-primary md-hue-2 style</h2></div></md-toolbar>
            <md-toolbar class="md-accent"><div class="md-toolbar-tools"><h2 class="md-flex">Using md-accent style</h2></div></md-toolbar>
            <md-toolbar class="md-accent md-hue-1"><div class="md-toolbar-tools"><h2 class="md-flex">Using md-accent md-hue-1 style</h2></div></md-toolbar>
            <md-toolbar class="md-accent md-hue-2"><div class="md-toolbar-tools"><h2 class="md-flex">Using md-accent md-hue-2 style</h2></div></md-toolbar>
            <md-toolbar class="md-warn"><div class="md-toolbar-tools"><h2 class="md-flex">Using md-warn style</h2></div></md-toolbar>
            <md-toolbar class="md-warn md-hue-1"><div class="md-toolbar-tools"><h2 class="md-flex">Using md-warn md-hue-1 style</h2></div></md-toolbar>
            <md-toolbar class="md-warn md-hue-2"><div class="md-toolbar-tools"><h2 class="md-flex">Using md-warn md-hue-2 style</h2></div></md-toolbar>              
         </md-card-content>
      </md-card>
         <div md-theme="customTheme">
            <md-toolbar class="md-primary"><div class="md-toolbar-tools"><h2 class="md-flex">Custom Theme</h2></div></md-toolbar>
            <hr/>
            <md-card>         
               <md-card-content layout="column"> 
                  <md-toolbar class="md-primary"><div class="md-toolbar-tools"><h2 class="md-flex">Using md-primary style</h2></div></md-toolbar>
                  <md-toolbar class="md-primary md-hue-1"><div class="md-toolbar-tools"><h2 class="md-flex">Using md-primary md-hue-1 style</h2></div></md-toolbar>
                  <md-toolbar class="md-primary md-hue-2"><div class="md-toolbar-tools"><h2 class="md-flex">Using md-primary md-hue-2 style</h2></div></md-toolbar>
                  <md-toolbar class="md-accent"><div class="md-toolbar-tools"><h2 class="md-flex">Using md-accent style</h2></div></md-toolbar>
                  <md-toolbar class="md-accent md-hue-1"><div class="md-toolbar-tools"><h2 class="md-flex">Using md-accent md-hue-1 style</h2></div></md-toolbar>
                  <md-toolbar class="md-accent md-hue-2"><div class="md-toolbar-tools"><h2 class="md-flex">Using md-accent md-hue-2 style</h2></div></md-toolbar>
                  <md-toolbar class="md-warn"><div class="md-toolbar-tools"><h2 class="md-flex">Using md-warn style</h2></div></md-toolbar>
                  <md-toolbar class="md-warn md-hue-1"><div class="md-toolbar-tools"><h2 class="md-flex">Using md-warn md-hue-1 style</h2></div></md-toolbar>
                  <md-toolbar class="md-warn md-hue-2"><div class="md-toolbar-tools"><h2 class="md-flex">Using md-warn md-hue-2 style</h2></div></md-toolbar>              
               </md-card-content>
            </md-card>
         </div>
      </div>
   </body>
</html>
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy angular material tutorial , angular 4 material , angular material2 , angular material example team

Output:


This tutorial provides most of the basics of all the below related informations such as angular material design , material design angular , angular material table , angularjs material , material angular , angular material icons , angular 2 material design , angular material template , angular materialize , angular material theme , angular material layout , material design angular 2 , angular material demo , angular material dialog , angular material form , angular material button , material angular 2 , angular material datepicker , angular material data table , angular material tutorial , angular material login form , material for angular 2 , angular material data grid , material ui angular , angular material calendar , angular material design table , angular material grid , google angular material , angular material components , angular 2 material ui , angular material autocomplete example , material ui angular 2 , angular material 2 demo , angular2 material demo , angular material template free , angular material design tutorial , angularjs material tutorial , material design for angular 2 , angular material tabs example , angular material ui , table angular material , angular material angular 2 , angular material layout align , what is angular material , angular material tabs , angular2 material example , angular 2 material tutorial , angular material login page , angular 2 material demo , angular material cdn , angular material design example , angularjs material design template , material angularjs , angular material grid list , angular material search bar , angular material vs bootstrap , angular material js , angular material range slider , angular material sidenav example , angular material form example , material angular icons , angular material datepicker example , angular material design icons , angular material design template , angular material bootstrap , materialize angular , angular material template free download , bootstrap material design angular , angular material table example

Related Searches to Angular Material Theme