【发布时间】:2021-08-31 01:05:45
【问题描述】:
我想在 Vaadin 14.6 应用程序中使用 Material 图标。我找到了 Lumo 和 Iron 图标 here(默认)的配方,但没有发现如何集成 Material 图标。 怎么实现?
注意:这个component 似乎不适用于 Vaadin 14.x
【问题讨论】:
标签: google-material-icons vaadin14
我想在 Vaadin 14.6 应用程序中使用 Material 图标。我找到了 Lumo 和 Iron 图标 here(默认)的配方,但没有发现如何集成 Material 图标。 怎么实现?
注意:这个component 似乎不适用于 Vaadin 14.x
【问题讨论】:
标签: google-material-icons vaadin14
基本上有三种方法。
如果你只使用几个图标。 https://fonts.google.com/icons 允许您将每个图标下载为 svg 或 png 文件。因此,您可以轻松地在 Vaadin 的 Image 组件中使用它们。
在 Vaadin 的网站上有培训视频,其中描述了与应用程序的主题和样式相关的各种内容,在 19:30 时间戳有一个关于如何配置自定义字体的章节:
https://vaadin.com/learn/training/v14-theming
材质图标只是一种字体,您可以将其包含在项目中。
将 webfont 文件放在 e.g. “src/main/webapp/fonts/MaterialIcons”(如果你有Spring Boot jar打包项目注意位置不同)并导入生成的css
@StyleSheet("context://fonts/MaterialIcons/materialicons.css")
其中 materialicons.css 内容例如:
@font-face {
font-family: 'MaterialIcons';
font-style: normal;
font-weight: 400;
src: local('Material Icons'),
local('MaterialIcons-Regular'),
url(MaterialIcons-Regular.woff2) format('woff2'),
url(MaterialIcons-Regular.woff) format('woff'),
url(MaterialIcons-Regular.ttf) format('truetype');
}
开发者体验不是最好的,因为您需要使用字符代码来使用图标,例如“搜索”图标接缝为“e8b6”等。所以设置span的文本内容或div 并定义元素的 css 以使用材质字体图标。
span.getElement().getStyles().set("font-family","MaterialIcons");
如果您需要在多个项目中使用多种字体,这是值得的。
已经存在 FontAwesome 的附加包。这很好地展示了如何构建此类附加组件。替换字体资源很简单,需要做更多的工作来为枚举生成图标名称列表,以便有更直观的 Java API 来使用图标。 https://github.com/google/material-design-icons/tree/master/font 中似乎有字体的标准代码点文件,因此可能可以使用与 FontAwesome 附加项目中类似的脚本。
【讨论】: