本文目标
利用阿里iconfont制作矢量文字图标
1、搜索需要的图标,比如我要搜索一个首页,如下图:
2.添加到购物车并打开,如下图
3.Add To Project,创建一个项目,下图中创建了演示的项目,然后点击confirm
4.点击Download code
5.下载完成解压
6.打开demo_index.html预览一下
收藏图标下面的这一串Unicode码就是图标
7.在安卓中使用
必须要写在strings中,然后在使用
8.两个自定义view
internal class IconFontButton @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : AppCompatButton(context, attrs, defStyleAttr) {
init {
val typeface = Typeface.createFromAsset(context.assets, "fonts/iconfont.ttf");
setTypeface(typeface)
}
}
class IconFontTextView
@JvmOverloads constructor(context: Context, attributeSet: AttributeSet?, defStyle: Int = 0) :
AppCompatTextView(context, attributeSet, defStyle) {
init {
val typeface = Typeface.createFromAsset(
context.assets,
"fonts/iconfont.ttf"
);
setTypeface(typeface)
}
}