【问题标题】:Is it possible to use the rgb color selection in the $mdThemingProvider是否可以在 $mdThemingProvider 中使用 rgb 颜色选择
【发布时间】:2015-07-10 15:46:33
【问题描述】:

我正在使用 angularjs 和 angular-material 开发一个 Firefox OS 应用程序;我的问题是我想让我的用户选择自定义他们的应用程序,所以我使用 tree md-slider 来选择红色、绿色和蓝色,我使用 rgb 和参数中的滑块模型来获得自定义颜色。 现在我想知道是否有可能做这样的事情:

myapp.config(['$mdThemingProvider',function($mdThemingProvider){
  $mdThemingProvider.theme('default')
    .primaryPalette('rgb(x,y,z)');
}]);

【问题讨论】:

  • 你试过了吗?结果是什么?为什么这个结果还不够?

标签: javascript angularjs angular-material


【解决方案1】:

使用默认主题,您只能选择:

  • 红色
  • 粉色
  • 紫色
  • 深紫色
  • 靛蓝
  • 蓝色
  • 浅蓝色
  • 青色
  • 蓝绿色
  • 绿色
  • 浅绿色
  • 石灰
  • 黄色
  • 琥珀色
  • 橙色
  • 深橙色
  • 棕色
  • 灰色
  • 蓝灰色

根据文档:https://material.angularjs.org/latest/#/Theming/01_introduction

如果您想要自定义颜色,则需要定义自己的自定义调色板

angular.module('myApp', ['ngMaterial'])
.config(function($mdThemingProvider) {
  $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('default')
    .primaryPalette('amazingPaletteName')
});

硒:https://material.angularjs.org/latest/#/Theming/03_configuring_a_theme

【讨论】:

  • 好的,谢谢我现在明白了! ...所以我将首先转换我的 r,g 和 b 值以获取颜色十六进制代码,然后我将使用该代码在我的自定义调色板中定义色调..谢谢!!!。
  • 没问题。或许你可以直接使用rgb语法,试试吧!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-07-15
  • 2011-04-15
  • 2015-04-22
  • 1970-01-01
  • 2010-10-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多