ttf图标使用

1、采用ttf图标生成工具网址https://icomoon.io/app/#/select,将需要的图标生成.ttf格式的文件

2、将.ttf文件放至assets文件下

3、自定义TextView

public class IconFontTextView extends AppCompatTextView {
 
    public IconFontTextView(Context context) {
        super(context);
    }

    public IconFontTextView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        Typeface  typeface = Typeface.createFromAsset(getContext().getAssets(), "iconfont.ttf");
        setTypeface(typeface);
    }

}

4、ttf图标生成工具网上查看图标编码并在string.xml中定义

<string name="ic_heart">\ue900</string>

5、使用图标

<com.lpf.demo.view.IconFontTextView
     android:id="@+id/iv_heart"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:textSize="32sp"
     android:textColor="@color/white"
     android:text="@string/ic_heart"/>

猜你喜欢

转载自blog.csdn.net/yufumatou/article/details/108762607