Issue
I'm learning to use Android Jetpack Compose. Now I have a Regular.otf font file in assets/font. I want to use it in Text.
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)
I tried some methods but none of them solved.
val fontFamily = FontFamily(
typeface = Typeface.createFromFile("commonui/src/main/assets/font/Regular.otf")
)
Text(
text = "Font",
style = TextStyle(fontFamily = fontFamily)
)
Solution
replace line with this
typeface = Typeface.createFromAsset(getAssets(),"font/Regular.otf")
Happy Coding!
Answered By - Praful Patel
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.