如何添加外部字体为Android应用程序
问题描述:
我一直在寻找一些时髦的字体,我的Android应用程序。但问题是怎样才能让我的Android应用程序支持的外部字体。
I was looking for some stylish fonts for my android application. but the problem is how can i make my android application supportable for external fonts.
感谢你。
答
您需要创建字体下的资产文件夹中的项目文件夹,并把你的TTF进去。然后在你的活动的onCreate()
You need to create fonts folder under assets folder in your project and put your TTF into it. Then in your Activity onCreate()
TextView myTextView=(TextView)findViewById(R.id.textBox);
Typeface typeFace=Typeface.createFromAsset(getAssets(),"fonts/mytruetypefont.ttf");
myTextView.setTypeface(typeFace);
请注意,并非所有的TTF会工作。当我尝试,它的工作只是一个子集(在Windows上他的名字写在小盘股的)。
Please note that not all TTF will work. While I was experimenting, it worked just for a subset (on Windows the ones whose name is written in small caps).