本文主要是介绍Font Awesome to android,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
下载字体库 http://fontawesome.dashgame.com/
在fonts文件夹中找到fontawesome-webfont.ttf
--------4.7版本之后,好像就没有fonts文件夹了--------
将.ttf文件拷至我们的项目目录assets目录下 ,没有就新建
像这样:
用法:创建一个fontManager类,用于管理字体
public class FontManager {public static final String ROOT = "fonts/";public static final String FONT_AWESOME = ROOT + "fontawesome-webfont.ttf";public static Typeface getTypeface(Context context, String font) {return Typeface.createFromAsset(context.getAssets(), font);}public static void markAsIconContainer(View v, Typeface typeface) {if (v instanceof ViewGroup) {ViewGroup vg = (ViewGroup) v;for (int i = 0; i < vg.getChildCount(); i++) {View child = vg.getChildAt(i);markAsIconContainer(child, typeface);}} else if (v instanceof TextView) {((TextView) v).setTypeface(typeface);}}}
view中的text 可以去找一个自己需要显示的图标,https://fontawesome.com/v4.7.0/icons/#
点击自己想要的图标后,如下所示unicode:f2b9,在布局中填入text=“”即可
<TextViewandroid:id="@+id/fonticon"android:layout_width="wrap_content"android:layout_height="wrap_content"android:gravity="center"android:text=""android:textColor="#44619d"android:textSize="50sp"android:onClick="facebook_onclick"/>
具体使用,传入view即可
FontManager.markAsIconContainer(findViewById(R.id.view), FontManager.getTypeface(this, FontManager.FONT_AWESOME));
这篇关于Font Awesome to android的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!