我有两个相同字体的权重。
根据https://stackoverflow.com/a/41678274/877682,我看到字体系列必须与安卓上的文件名匹配,所以我将字体文件命名为"Font name Regular.ttf“和”font name SemiBold.ttf“。
然后,我尝试包含半粗体的via
font-family: [Font name];
font-weight: 600;"然而,Android找不到它,默认使用sans-serif字体(我假设它是Roboto)。
在这种情况下,预期的字体文件命名系统是什么?我需要创建单独的安卓和ios CSS文件,然后简单地命名为在安卓上使用font-family: [Font name] Semibold;吗?
发布于 2018-02-03 07:21:05
如果没有单独的iOS和Android文件,在Android上每个字体的粗细都有font-family定义,我就没有办法做到这一点。
因为Android需要精确的字体文件名,所以我不能对所有标签使用默认字体,并相应地改变字体粗细,就像我在iOS上所做的那样。
app.css:
@import "~/platform.css"; /* Platform-dependent styles */
@import "~/app-common.css"; /* Platform-independent styles */platform.ios.css:
/* Default font: used everywhere except classes below */
Label {
font-family: "My Body Font"; /* Exact font name */
}
.heading-1, .heading-2, .heading-2-subtext {
font-family: "My Display Font"; /* Exact font name */
}platform.android.css:
.heading-1, .heading-2 {
font-family: "MyDisplayFont-Bold"; /* file name: MyDisplayFont-Regular-Bold.otf */
}
.heading-2-subtext {
font-family: "MyDisplayFont-Regular"; /* file name: MyDisplayFont-Regular.otf */
}
.heading-3 {
font-family: "MyBodyFont-SemiBold"; /* file name: MyBodyFont-SemiBold.otf */
}
.body-text {
font-family: "MyBodyFont-Regular"; /* file name: MyBodyFont-Regular.otf */
}app-common.css:
.heading-1 {
font-size: 36;
font-weight: bold; /* Used by iOS, ignored by Android */
}
.heading-2 {
font-size: 24;
font-weight: bold; /* Used by iOS, ignored by Android */
}
.heading-3 {
font-size: 16;
font-weight: 600; /* semi-bold, Used by iOS, ignored by Android */
}
.body-text {
font-size: 14;
}据我所知,我可以将所有的平台样式转移到font-weight -ios.css中,因为安卓字体的粗细是由font-family声明控制的。
但是,由于我在app-common.css中为每个类定义了font-size,因此在这里定义font-weight对我来说更有意义。
发布于 2018-10-24 19:22:42
我认为这里最好的方法是使用@font-face创建一个由所有文件组成的字体系列。
如果我有一个字体的三个权重,并想用它们构建一个族,我会这样做:
@font-face {
font-family: 'Open Sans';
src: url('~/fonts/Open Sans Regular.tff') format('truetype');
font-weight: 300;
}
@font-face {
font-family: 'Open Sans';
src: url('~/fonts/Open Sans Light.tff') format('truetype');
font-weight: 100;
}
@font-face {
font-family: 'Open Sans';
src: url('~/fonts/Open Sans Bold.tff') format('truetype');
font-weight: 500;
}然后,我可以在其他地方使用它,通过:
Label {
font-family: 'Open Sans';
font-weight: 300; // Regular Open Sans
}
Label.mod-light {
font-weight: 100; // Light Open Sans
}
Label.mod-bold {
font-weight: 500; // Bold Open Sans
}这种方法的好处是,您不需要向css或HTML添加更多属性来支持依赖于每个设备的字体粗细。
https://stackoverflow.com/questions/48183266
复制相似问题