首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

让TextView应用指定的字体(Typeface)

2012-08-26 
让TextView使用指定的字体(Typeface)public class FontTest extends Activity {/** Called when the activ

让TextView使用指定的字体(Typeface)

public class FontTest extends Activity {      /** Called when the activity is first created. */      @Override      public void onCreate(Bundle savedInstanceState) {          super.onCreate(savedInstanceState);          setContentView(R.layout.main);            /*         * 必须事先在assets底下创建一fonts文件夹 并放入要使用的字体文件(.ttf)         * 并提供相对路径给creatFromAsset()来创建Typeface对象         */        Typeface fontFace = Typeface.createFromAsset(getAssets(), "fonts/raw.ttf"); // 字体文件必须是true type font的格式(ttf);            // 当使用外部字体却又发现字体没有变化的时候(以 Droid Sans代替),通常是因为            // 这个字体android没有支持,而非你的程序发生了错误                   TextView text = (TextView)findViewById(R.id.text);          text.setTypeface(fontFace);          text.setText("Hello World!");          text.setTextSize(50);      }  } 

http://edison-cool911.iteye.com/blog/726725

热点排行