How to use otf type font file in Android Compose?(如何在Android编写中使用OTF型字体文件?)
问题描述
我正在学习使用Android Jetpack Compose。 现在我在Assets/FONT中有一个Regular.otf字体文件。我想在文本中使用它。
java.lang.RuntimeException: Font asset not found /commonui/src/main/assets/font/Regular.otf
at android.graphics.Typeface.createFromFile(Typeface.java:998)
at android.graphics.Typeface.createFromFile(Typeface.java:1012)
我尝试了一些方法,但都没有解决问题。
val fontFamily = FontFamily(
typeface = Typeface.createFromFile("commonui/src/main/assets/font/Regular.otf")
)
Text(
text = "Font",
style = TextStyle(fontFamily = fontFamily)
)
推荐答案
将该行替换为
TypeFace=Typeface.createFromAsset(getAssets(),";font/Regular.otf";)
编码快乐!
这篇关于如何在Android编写中使用OTF型字体文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!