如何在 Jetpack Compose Desktop 中加载字体? [英] How to load Fonts in Jetpack Compose Desktop?

查看:59
本文介绍了如何在 Jetpack Compose Desktop 中加载字体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Jetpack Compose for android 中,您可以这样做:

In Jetpack Compose for android you can do this:


val fontFamily = FontFamily(
    Font(
        resId = R.font.my_font_400_regular,
        weight = FontWeight.W400,
        style = FontStyle.Normal
    ),
    Font(
        resId = R.font.my_font_400_italic,
        weight = FontWeight.W400,
        style = FontStyle.Italic
    )
)


但对于桌面,文件结构是不同的,我无法访问 R.font.my_font_400_regular,因为R"是 Android 资源功能.

But for Desktop the Filestructure is different and I have no Access to R.font.my_font_400_regular since 'R' is a Android Resource feature.

推荐答案

将您的 .ttf 字体文件放入 src >主要 >资源 文件夹.然后使用:

Put your .ttf font file in the src > main > resources folder. And then use:

val fontFamily = FontFamily(
    Font(
        resource = "font.ttf",
        weight = FontWeight.W400,
        style = FontStyle.Normal
    )
)

这篇关于如何在 Jetpack Compose Desktop 中加载字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆