skip to Main Content

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?

2

Answers


  1. Chosen as BEST ANSWER

    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)
    

  2. You can only show a TextView as Light, Regular and Condensed if the font that you’re referencing allows those styles.

    private TextView AB;

    Typeface someFontName-condensed = Typeface.createFromAsset(getAssets(), "assets/NameOfFont-condensed.ttf");

    AB = (TextView) findViewById(R.id.myTextViewId);
    AB.setTypeface(someFontName-condensed);

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search