/**
* Create a Font declaration from a file in the assets directory. The content of the [File] is
* read during construction.
*
* @param assetManager Android AssetManager
* @param path full path starting from the assets directory (i.e. dir/myfont.ttf for
* assets/dir/myfont.ttf).
* @param weight The weight of the font. The system uses this to match a font to a font request
* that is given in a [androidx.compose.ui.text.SpanStyle].
* @param style The style of the font, normal or italic. The system uses this to match a font to a
* font request that is given in a [androidx.compose.ui.text.SpanStyle].
*/
@ExperimentalTextApi
@OptIn(InternalPlatformTextApi::class, ExperimentalTextApi::class)
@Stable
fun Font(
assetManager: AssetManager,
path: String,
weight: FontWeight = FontWeight.Normal,
style: FontStyle = FontStyle.Normal
): Font = AndroidAssetFont(assetManager, path, weight, style)
3条答案
按热度按时间gorkyyrv1#
是的,有一个默认方法,它将
AssetManager
作为参数:现在访问字体像这样!
kyvafyod2#
1.在res中创建字体目录(res/font)
1.复制res中的.ttf字体/font
1.找到Type.kt文件(在ui/theme目录中)
1.在Type.kt中创建字体变量
1.你可以设置字体系列到特定的排版如body 1,h1,h2,...
编辑:要更改材料3的字体,请在Type.kt中添加以下内容
ozxc1zmp3#
实际上,在composition中,通常有一个名为Typography.kt的类,它被
MaterialTheme
Composable使用。正如主题代码实验室中所描述的,正确的方法是修改这个类以向其添加字体。实际上,你可以创建自己的mAppTheme
来覆盖Material的。https://youtu.be/DDd6IOlH3io?t=6m27s
本视频演示如何实现自定义调色板,但也可以采用类似的方法来实现自定义版式。
查看JetSnack示例应用https://github.com/android/compose-samples