Android 字体图片设置

使用字体图片,图片属性更容易设置,图片如同字体一样,可设置颜色,大小,以下为使用步骤

1.到  Iconfont-阿里巴巴矢量图标库 注册账号,首页图标说明:


2.图标的选择与下载


3.下载文件说明(Android部分)


4.在项目中使用,把3中的ttf文件放在assets文件夹下:

5.代码应用,若按照阿里矢量图标官网的使用方法,则相当麻烦,为简单使用可自定义View,直接当作控件使用:

自定义控件代码:

package com.doctor.doctorhelper.view;

import android.content.Context;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.widget.TextView;

/**
 * Created by public on 2016/12/22.
 */
public class IconFontTextView extends TextView{
    public IconFontTextView(Context context) {
        super(context);
        init(context);
    }

    public IconFontTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public IconFontTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    private void init(Context context){
        Typeface iconfont=Typeface.createFromAsset(context.getAssets(),"iconfont/iconfont.ttf");
        setTypeface(iconfont);
    }
}

可直接使用,设置大小,颜色:




猜你喜欢

转载自blog.csdn.net/androidforwell/article/details/53886498