Android使用自定义字体

来源:互联网 发布:网络特产商城行业分析 编辑:程序博客网 时间:2024/05/16 15:49

在Android Studio中main目录下创建assets目录(如果没有的话)

我们也可以通过项目根目录下的.iml文件设置assets的目录,添加如下节点

<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />  


然后在下面添加fonts目录并把ttf文件拷进去


然后在代码中实现

AssetManager mgr=getAssets();//得到AssetManagerTypeface tf= Typeface.createFromAsset(mgr, "fonts/thin.TTF");//根据路径得到TypefacemTextClock=(TextClock)findViewById(R.id.textClock);mTextClock.setTypeface(tf);//设置字体



0 0
原创粉丝点击