天天看点

TextView使用指定的TTF字库

  public class FontTest extends Activity {     

          @Override     

          public void onCreate(Bundle savedInstanceState) {     

          super.onCreate(savedInstanceState);     

          setContentView(R.layout.main);     

          Typeface font = Typeface.createFromAsset(getAssets(), "fonts/sans.ttf");    

           // 字体文件必须是true type font的格式(ttf);   

          // 当使用外部字体却又发现字体没有变化的时候(以 Droid Sans代替),通常是因为这个字体android没有支持,而非你的程序发生了错误            

           TextView text = (TextView)findViewById(R.id.text);     

            text.setTypeface(font);     

            text.setText("Hello Android!");     

            text.setTextSize(40);     

            }     

}