搜索
您的当前位置:首页正文

Android App icon font集成攻略

来源:二三娱乐

前言
近期项目中有用到Icon Font,个人对Icon Font也比较喜欢,写点文章推广推广。喜欢探讨Android开发技术的同学可以加学习小组QQ群: 193765960

Icon Font

Icon Font出来已经有一段时间了,网上的资料也比较多。
其优点也是很明显的:

  • 省资源,大约相比切图,可以节省1/3以上的资源
  • 使用方便,就像设置普TextView一样设置需要显示的图标,并且颜色可以随意设置

唯一不太方便的是只适用于纯色的图标

Android中集成使用

UI提供的资源

Android 集成Icon Font

  1. assets目录下放入资源包iconfont.ttf
  2. 在App 的Application的onCreate()方法中设置系统字体
@Override
public void onCreate() {
    super.onCreate();
    String fonts = "fonts/iconfont.ttf";//字体控制
    FontsUtils.setDefaultFont(this, "SERIF", fonts);
 }

设置字体的工具类,网上实在是太多了,大家自己去找一个就好。

用法

在xml的layout布局文件中,直接使用Textview

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@mipmap/fab_bg"
    android:gravity="center"
    android:text="\ue623"
    android:textColor="@color/gray6"
    android:textSize="16dp"
    android:typeface="serif" />

其中:

  • \ue623是icon的Unicode码,这个UI会提供。
  • android:textColor:设置图标的颜色
  • android:textColor:设置图标的尺寸
  • android:typeface="serif" :这个就是我们的字体使用的字体库,因为我们在Application中对serif做了更改,所以这里使用serif.

分享是一种美德,转发是对作者最好的支持,欢迎大家加QQ群积极参与技术讨论。

Top