Search code examples
androidcsstextview

How to set font weight programmatically?


I want to change the font weight in TextView but i can't find the required method.

How can I do it without creating a new font?


Solution

  • I have found the right answer. There is the static method:

    open static fun create(family: Typeface?, weight: Int, italic: Boolean): Typeface

    For example, if you want the font weight to be 700:

    var text = findViewById<TextView>(R.id.text)
    text.typeface=Typeface.create(null,700,false)