如何更改角度材质md-主按钮文字颜色?

Joh*_*hnC 3 material angularjs angular-material

基本上我不能为我的生活弄清楚如何使用角度材料和其他任何使用md-primary背景颜色设置按钮的文本颜色.

我用来创建主题的代码是

var customPrimary = {
        '50': '#7de3cf',
        '100': '#69dec8',
        '200': '#54dac0',
        '300': '#3fd5b8',
        '400': '#2dceaf',
        '500': '#28b99d',
        '600': '#23a48b',
        '700': '#1f8f79',
        '800': '#1a7a68',
        '900': '#166556',
        'A100': '#92e8d7',
        'A200': '#a7ecdf',
        'A400': '#bcf1e7',
        'A700': '#115044'
    };
    $mdThemingProvider
        .definePalette('customPrimary',
        customPrimary);
    $mdThemingProvider.theme('buttons')
        .primaryPalette('customAccent');
Run Code Online (Sandbox Code Playgroud)

然而,无论我尝试什么,我都可以得到文本颜色,#fff除非我使用CSS和!important我想避免,因为它意味着重写几个选择器.

Bry*_*n K 6

来自文档:

angular.module('myApp', ['ngMaterial'])
.config(function($mdThemingProvider) {
  $mdThemingProvider.definePalette('amazingPaletteName', {
    '50': 'ffebee',
    ...
    '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')
});
Run Code Online (Sandbox Code Playgroud)

这里最重要的是contrastDarkColors/ contrastLightColors."对比度"颜色是显示在按钮上的文本(或图标)颜色.

我猜你会想要类似的东西

'contrastDefaultColor': 'light',
'contrastDarkColors': ['50', '100', '200', '300', 'A100', 'A400']
Run Code Online (Sandbox Code Playgroud)

编辑:如果你出于某种原因想要一个按钮上的颜色,创建一个具有!important的类很好,例如

.md-button.cyan-text {
    color: cyan !important;
}
Run Code Online (Sandbox Code Playgroud)

<md-button class="md-primary md-raised cyan-text">Hello world</md-button>
Run Code Online (Sandbox Code Playgroud)