How to change fontFamily of TextView in Android

后端 未结 30 2462
感动是毒
感动是毒 2020-11-22 01:05

So I\'d like to change the android:fontFamily in Android but I don\'t see any pre-defined fonts in Android. How do I select one of the pre-defined ones? I don\'

30条回答
  •  长发绾君心
    2020-11-22 01:35

    This is the way to set the font programmatically:

    TextView tv = (TextView) findViewById(R.id.appname);
    Typeface face = Typeface.createFromAsset(getAssets(),
                "fonts/epimodem.ttf");
    tv.setTypeface(face);
    

    put the font file in your assets folder. In my case I created a subdirectory called fonts.

    EDIT: If you wonder where is your assets folder see this question

提交回复
热议问题