首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在材料工具栏上有一个自定义的背景颜色?

如何在材料工具栏上有一个自定义的背景颜色?
EN

Stack Overflow用户
提问于 2020-05-03 14:50:23
回答 1查看 2.7K关注 0票数 0

我为应用程序制作了一个带有背景颜色的定制主题:

代码语言:javascript
复制
@import '~@angular/material/theming';

@include mat-core();

$custom-theme-primary: mat-palette($mat-lime);
$custom-theme-accent: mat-palette($mat-orange, A200, A100, A400);
$custom-theme-warn: mat-palette($mat-red);

$custom-theme: mat-light-theme($custom-theme-primary, $custom-theme-accent, $custom-theme-warn);

$custom-background-color: map_get($mat-grey, 0);
$background: map-get($custom-theme, 'background');
$background: map_merge($background, ('background': $custom-background-color));
$custom-theme: map_merge($custom-theme, ('background': $background));

@include angular-material-theme($custom-theme);

现在,我正在尝试让包含右手按钮的mat-toolbar具有与mat-card背景颜色相同的白色。

但是工具栏的背景仍然是灰色的。

我希望没有包含此按钮的工具栏,但这是我发现它对齐的方式。

我确信有一些CSS方法可以实现这一点,但我不喜欢深入研究CSS黑客。我认为有角质的材料是为了保护我。

模板标记是:

代码语言:javascript
复制
<mat-card>
  <mat-card-content>
    <mat-toolbar color="background">
      <span class="fill-remaining-space"></span>
      <button mat-fab color="accent" (click)="generateSoundtrack()">
        <mat-icon mat-icon>add</mat-icon>
      </button>
    </mat-toolbar>
  </mat-card-content>
</mat-card>

与模板配套的CSS文件:

代码语言:javascript
复制
.fill-remaining-space {
  flex: 1 1 auto;
}

.soundtrack-action {
  padding-left: 30px;
}

.soundtrack {
  padding-bottom: 50px;
}

mat-icon {
  cursor: pointer;
}

更新:我可以通过以下主题配置来解决不同背景颜色的问题:

代码语言:javascript
复制
// Applying a custom theme
$palette-primary: mat-palette($mat-lime);
$palette-accent: mat-palette($mat-orange);
$palette-warn: mat-palette($mat-red);
$standard-light-theme: mat-light-theme($palette-primary, $palette-accent, $palette-warn);
@include angular-material-theme($standard-light-theme);

// Changing some palette properties of a theme and applying it to a component
$background: map-get($standard-light-theme, background);
$bg-color: #FFFFFF;
$background: map_merge($background, (background: $bg-color, app-bar: $bg-color));
$custom-light-theme: map_merge($standard-light-theme, (background: $background));
@include mat-toolbar-theme($custom-light-theme);
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-03 15:27:51

实现这一点有几种方法,在我将要向您展示的示例中,为button按钮组件使用另一个主题,您可以为任何材料组件(可变材料-成分-主题)使用另一个主题。

你还有其他选择:

这是工作示例stackblitz

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61576460

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档