使用自己的字体
做Android开发的时候,一些软件会要求一些特殊字体,我们需要引入外部的ttf格式的字体到程序中,具体操作步骤为:
在安卓应用程序的目录assets中新建fonts目录,将我们需要使用的ttf字体文件复制进去,然后代码:
// 得到TextView控件对象
TextView textView = (TextView) findViewById(R.id.custom);
// 将字体文件保存在assets/fonts/目录下,www.linuxidc.com创建Typeface对象
Typeface typeFace = Typeface.createFromAsset(getAssets(),"fonts/DroidSansThai.ttf");
// 应用字体
textView.setTypeface(typeFace);
ttf格式是一般下载的字体格式
没有assets目录怎么办?
需要自己创建,我是使用android studio,需要增加assets目录,如在:xxx/src/main/assets
XXX代表你的项目的路径,assets放在src\main目录下。