热文导读 | 点击标题阅读
作者:hongjay
链接:https://www.jianshu.com/p/5658a19a66e5
前情提要:公司不让UI干重活,让我自己找图标。然后推荐使用这个开源库。优质Icon多到数不清,还可以随意修改icon的颜色,大小,使用起来略爽。简书和掘金上搜不到相关博客,踩了点坑,凡事只能靠自己啊。
项目demo地址请点击这里:https://github.com/zjxuzhj/IconFontDemo
一、添加依赖
compile "com.mikepenz:iconics-core:2.8.2@aar"
compile 'com.android.support:appcompat-v7:25.1.0'
二、选择需要依赖的图标库
每个图标库都有自己的网站,可以在上面挑选自己喜欢的图标,查找对应的图标id
Font Awesome:http://fontawesome.dashgame.com/
ionicons:http://ionicons.com/
已Font Awesome 为例
三、icon前缀和依赖库对应表
Google Material Design Icons
"gmd"
ORIGINAL by Google compile 'com.mikepenz:google-material-typeface:+.original@aar'Material Design Iconic Font
"gmi"
Google Material Iconic compile 'com.mikepenz:material-design-iconic-typeface:+@aar'Fontawesome
"faw"
compile 'com.mikepenz:fontawesome-typeface:+@aar'Meteocons
"met"
compile 'com.mikepenz:meteocons-typeface:+@aar'Octicons
"oct"
compile 'com.mikepenz:octicons-typeface:+@aar'Community Material
"cmd"
compile 'com.mikepenz:community-material-typeface:+@aar'Weather Icons
"wic"
compile 'com.mikepenz:weather-icons-typeface:+@aar'Typeicons
"typ"
compile 'com.mikepenz:typeicons-typeface:+@aar'Entypo
"ent"
compile 'com.mikepenz:entypo-typeface:+@aar'Devicon
"dev"
compile 'com.mikepenz:devicon-typeface:+@aar'Foundation Icons
"fou"
compile 'com.mikepenz:foundation-icons-typeface:+@aar'Ionicons
"ion"
compile 'com.mikepenz:ionicons-typeface:+@aar'
四、以Drawable方式使用(在代码中动态替换图片)
new IconicsDrawable(this)
.icon(FontAwesome.Icon.faw_android) //icon Id
.color(Color.RED)
.sizeDp(24) //icon 大小 dp值
五、直接在XML文件中使用
使用开源库自定义的控件
使用普通控件(需要注册)
有两种方法在onCreate函数中加入代码
然后就可以使用了
六、这里有一个坑
在所有步骤都正确完成后,AS还是会红线报错
翻遍了issues,有说把
xmlns:app="http://schemas.android.com/apk/res-auto"
改成
xmlns:app="http://schemas.android.com/apk/tool"
然而并没有软用。
https://github.com/mikepenz/Android-Iconics/issues/174
看到了这个issue,直接添加
Iconics.init(getApplicationContext());
Iconics.registerFont(new GoogleMaterial());
//注:应该和 LayoutInflaterCompat.setFactory(getLayoutInflater(),
new IconicsLayoutInflater(getDelegate()));作用类似
然后报着试一试的心态,直接运行,竟然可以!果然是我太年轻么!!!
七、总结
使用起来实在是方便,对比阿里的Iconfont。Icon质量也挺不错。
Android-Iconics库的地址
还有一个类似的库Android-Iconify的库地址 。
参考:http://blog.csdn.net/cuipp0509/article/details/60778152
如你有好的文章想和大家分享欢迎投稿,直接向我投递文章链接即可
最后,欢迎大家加入我们的知识星球,第二期开期起航火热进行中,已有近1000人加入学习:
欢迎大家尽早加入,这期是到2019年3月10日结束,所以越早加入越好,优惠活动结束,现入圈费用由79元提至89元,以后每满100人费用增加10元~
微信扫描或者点击上方二维码领取Android\Python\AI\Java等高级进阶资源
更多学习资料点击下面的“阅读原文”获取