最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

基于?angular?material?theming?機(jī)制修改?mat-toolbar?的背景色(示例詳解)

 更新時(shí)間:2022年10月06日 09:16:33   作者:dudu  
最近在學(xué)習(xí)?angular,記錄一下昨天的進(jìn)展,解決的問題是通過?theme?的配置修改?mat-toolbar?的背景色,避免對(duì)色彩的硬編碼,這篇文章主要介紹了基于?angular?material?theming?機(jī)制修改?mat-toolbar?的背景色,需要的朋友可以參考下

最近在學(xué)習(xí) angular,記錄一下昨天的進(jìn)展,解決的問題是通過 theme 的配置修改 mat-toolbar 的背景色,避免對(duì)色彩的硬編碼。

首先通過 mat-toolbar (以下統(tǒng)一稱為 toolbar)的實(shí)現(xiàn)源代碼 _toolbar-theme.scss 得知背景色來自 theme 中 background palette 的 app-bar。

background: theming.get-color-from-palette($background, app-bar);

于是通過下面的 scss 代碼修改 app-bar 的顏色值

$app-bar-background: map-get(mat.$grey-palette, 900);
$background-palette: map-get($theme, background);
$background-palette: map-merge($background-palette, (app-bar: $app-bar-background));
$theme: map-merge($theme, (background: $background-palette));

注:第1行代碼就是我們想使用的背景色

但發(fā)現(xiàn)上面的修改對(duì) toolbar 沒有起作用,而通過下面的代碼可以拿到修改后的背景色

$background-palette: map-get($theme, background);
background-color: mat.get-color-from-palette($background-palette, app-bar);

看來 mat-toolbar 不是通過 theme 的 background 獲取背景色的。

查看的 define-light-theme 的實(shí)現(xiàn)源碼 _theming.scss 發(fā)現(xiàn)下面的代碼

@if $accent != null {
    @warn $_legacy-theme-warning;
    @return private-create-backwards-compatibility-theme(_mat-validate-theme((
      _is-legacy-theme: true,
      color: _mat-create-light-color-config($primary, $accent, $warn),
    )));
  }

由此猜測 toolbar 可能是 legacy theme

進(jìn)一步查看 toolbar 的實(shí)現(xiàn)源碼 _toolbar-theme.scss

@mixin theme($theme-or-color-config) {
  $theme: theming.private-legacy-get-theme($theme-or-color-config);
  @include theming.private-check-duplicate-theme-styles($theme, 'mat-toolbar') {
    $color: theming.get-color-config($theme);
    $density: theming.get-density-config($theme);
    $typography: theming.get-typography-config($theme);
    // ...
  }
}

的確是 legacy theme 。

最終在之前的代碼基礎(chǔ)上添加下面的代碼解決了問題。

$color-palette: map-get($theme, color);
$color-background-palette: map-get($color-palette, background);
$color-background-palette: map-merge($color-background-palette, (app-bar: $app-bar-background));
$color-palette: map-merge($color-palette, (background: $color-background-palette));
$theme: map-merge($theme, (color: $color-palette));

在解決這個(gè)問題過程中搜索到的參考材料

Changing the background color in an Angular Material theme

How to get the current angular theme's color of a specific component

Allow overriding of theme background and foreground colors

到此這篇關(guān)于基于 angular material theming 機(jī)制修改 mat-toolbar 的背景色的文章就介紹到這了,更多相關(guān)angular material theming 修改背景色內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

昆明市| 和平区| 杨浦区| 云林县| 沁源县| 托克托县| 鸡东县| 西和县| 汉川市| 锡林郭勒盟| 长顺县| 东方市| 金溪县| 赤城县| 大安市| 无极县| 江永县| 株洲县| 阿克| 邓州市| 应用必备| 平谷区| 开远市| 南宫市| 浦城县| 永丰县| 永定县| 浦县| 启东市| 桂林市| 鹤庆县| 和田县| 色达县| 略阳县| 兰西县| 棋牌| 阿克| 休宁县| 永济市| 永登县| 正定县|