use custom font in paint object typeface field

94 views Asked by At

I have a custom font defined in my style file:

   <style name="TextCustomGood" parent="TextParent">
        <item name="android:textSize">@dimen/mediumSize</item>
        <item name="font">@font/serranopro_bold</item>
    </style>

I want to use it in my custom drawable object to draw some text in that font and font size. I am trying the below but it is not using that font:

val paint = Paint()
paint.isAntiAlias = true
paint.typeface = Typeface.defaultFromStyle(R.style.TextCustomGood)
canvas.draw("Hello World", 0, 0, paint)

please tell me what i am doing wrong. I have already looked at all the other similar questions but those are not helping me so please do not mark as duplicate.

0

There are 0 answers