欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

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

首先通過 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)上面的修改對 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)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論