IconFont_Android的使用和获取
说下自己在使用IconFont过程中遇到的一些问题
1、Font asset not found iconfont.ttf
这是因为自己没注意到Android studio的assets文件夹的位置跟eclipse的不太一样
Android studio路径为:项目名/app/src/main/assets
Eclipse路径为:项目名/assets
2、在项目中大量使用时可以自定义个view,以减少代码重复,如下
import android.content.Context; import android.graphics.Typeface; import android.util.AttributeSet; import android.widget.TextView; /** * Created by laisixiang on 2015/12/28. */ public class IconFontView extends TextView { public IconFontView(Context context) { super(context); } public IconFontView(Context context, AttributeSet attrs) { super(context, attrs); init(); } public IconFontView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(); } private void init() { Typeface iconfont = Typeface.createFromAsset(getContext().getAssets(), "iconfont.ttf"); this.setTypeface(iconfont); } }在xml中引用记得全名
<com.app.views.IconFontView android:id="@+id/iconfont android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/icon_to"/>
图标获取网站:http://www.iconfont.cn/collections
得到.ttf方法:http://blog.csdn.net/a345017062/article/details/46455745
摘要
1、首先登录网站,搜索你要用的Icon,把它们加入购物车(点击就可以)。
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
copyright © 2008-2019 亿联网络 版权所有 备案号:粤ICP备14031511号-2