Search code examples
androidtextviewandroid-custom-viewandroid-fontsandroid-typeface

Best way to assign font typeface to textview


I wonder what would be the best way to assign a font typeface to a TextView view? Is it better to create a custom TextView class which extends TextView or use setTypeFace attribute?


Solution

  • create folder assets(src/main/assets/ in AndroidStudio) and make a sub-folder fonts , copy your fonts in them

     Typeface tf = Typeface.createFromAsset(getAssets(),
        "fonts/youi.ttf");
     TextView tv = (TextView) findViewById(R.id.edit_t);
     tv.setTypeface(tf);