How to change fontFamily of TextView in Android

后端 未结 30 3129
感动是毒
感动是毒 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:32

    To set the font by program, write...

         TextView tv7 = new TextView(this);
         tv7.setText(" TIME ");    
         tv7.setTypeface(Typeface.create("sans-serif-condensed",Typeface.BOLD));
         tv7.setTextSize(12);
         tbrow.addView(tv7);
    

    The name "sans-serif-condensed" is referenced from fonts.xml file which should be created in app--> res--> values folder and it holds the fonts in it.

    
    
        sans-serif-light
        sans-serif-medium
        sans-serif
        sans-serif-condensed
        sans-serif-black
        sans-serif-thin
    
    

    Hope this is clear!

提交回复
热议问题