【问题标题】:How to create multiple theme in material angular?如何在材质角度创建多个主题?
【发布时间】:2015-05-11 16:34:21
【问题描述】:

我想在我的应用程序中应用蓝色、浅蓝色、绿色和橙色阴影。我正在使用材质角度主题部分。但不知道如何使用..我必须创建 css 吗?或js或指令..

【问题讨论】:

  • 如何为每个主题创建css类??
  • 你能给我们举个例子吗?因此,我们可以为您提供更好的帮助。

标签: angularjs angular-material


【解决方案1】:

1.) 先通过theme documentation here

2.) 从调色板中挑选颜色 (link)

3.) 使用您想要的颜色创建您自己的自定义主题,并在 app.config 中定义它。

app.config(function($mdThemingProvider) {

    $mdThemingProvider.theme('default')
          .primaryPalette('blue')
          .accentPalette('indigo')
          .warnPalette('red')
          .backgroundPalette('grey');

    $mdThemingProvider.theme('custom')
          .primaryPalette('grey')
          .accentPalette('deep-purple')
          .warnPalette('green')

    //create yr own palette 
    $mdThemingProvider.definePalette('amazingPaletteName', {
        '50': 'ffebee',
        '100': 'ffcdd2',
        '200': 'ef9a9a',
        '300': 'e57373',
        '400': 'ef5350',
        '500': 'f44336',
        '600': 'e53935',
        '700': 'd32f2f',
        '800': 'c62828',
        '900': 'b71c1c',
        'A100': 'ff8a80',
        'A200': 'ff5252',
        'A400': 'ff1744',
        'A700': 'd50000',
        'contrastDefaultColor': 'light',    // whether, by default, text         (contrast)
                                    // on this palette should be dark or light
        'contrastDarkColors': ['50', '100', //hues which contrast should be 'dark' by default
         '200', '300', '400', 'A100'],
        'contrastLightColors': undefined    // could also specify this if default was 'dark'
    });

   $mdThemingProvider.theme('custom2')
        .primaryPalette('amazingPaletteName')

}

4.) 然后在你的 html 上你可以使用这些主题

<div>
   <md-button class="md-primary">I will be blue (by default)</md-button>
   <div md-theme="custom">
      <md-button class="md-primary">I will be grey(custom)</md-button>
   </div>
   <div md-theme="custom2">
      <md-button class="md-primary">I will be red(custom2)</md-button>
   </div>
</div>

【讨论】:

  • 我添加了相同的代码,但托盘的背景颜色仍然没有改变.. :(
  • 后台 (github.com/angular/material/issues/1450) 存在问题,已在最新版本中修复。尝试更新你的角度材料。
  • 我想用白色作为主要颜色,我该怎么做?
  • 您应该按照答案中的第 3 步,在定义调色板时使用不同深浅的白色。
猜你喜欢
  • 2018-05-12
  • 2019-07-02
  • 2016-01-19
  • 2019-08-29
  • 2018-08-18
  • 1970-01-01
  • 1970-01-01
  • 2015-04-20
  • 2018-12-08
相关资源
最近更新 更多