android使用Font Awesome字体图标
2015-04-06 10:54
549 查看
Font Awesome的网址见http://fontawesome.dashgame.com/,Font Awesome提供可缩放的矢量图标,可以使用CSS所提供的所有特性对它们进行更改,包括:大小、颜色、阴影或者其它任何支持的效果。仅一个Font Awesome字库,就包含了与网页相关的所有形象图标。无论在任何尺寸下,可缩放的矢量图形都会为您呈现出完美的图标。Font Awesome的矢量图标,将使您的网站在视网膜级的高分屏上大放异彩。
那么,真强大的一个网页字体图标库可不可以用在安卓上呢,答案是可以的。
首先我们从文章前面的网址里下载最新的库,解压后再fonts目录下找到fontawesome-webfont.ttf,将其拷至我们的项目目录assets目录下,然后从github上下载一个字符串资源放到res目录下的values目录,网址见https://github.com/liltof/font-awsome-for-android
开始编码前看效果图
从效果图看出,我们没有用一张图片,就达到了这个效果,这一切都是依赖于字体,首先,创建自定义字体
然后是布局,简单布局了下
然后为每个TextView设置字体
如果你想改变图标大小和颜色,只要修改字体的大小和颜色即可,也就是说只要修改TextView的textSize和textColor。
更多使用效果待你去发现。
源码下载
http://download.csdn.net/detail/sbsujjbcy/8567213
那么,真强大的一个网页字体图标库可不可以用在安卓上呢,答案是可以的。
首先我们从文章前面的网址里下载最新的库,解压后再fonts目录下找到fontawesome-webfont.ttf,将其拷至我们的项目目录assets目录下,然后从github上下载一个字符串资源放到res目录下的values目录,网址见https://github.com/liltof/font-awsome-for-android
开始编码前看效果图
从效果图看出,我们没有用一张图片,就达到了这个效果,这一切都是依赖于字体,首先,创建自定义字体
Typeface font = Typeface.createFromAsset(getAssets(), "fontawesome-webfont.ttf");
然后是布局,简单布局了下
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="${relativePackage}.${activityClass}" > <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:background="#fff" > </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="60dp" android:background="#eee" android:orientation="horizontal" > <TextView android:id="@+id/tab1" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:gravity="center" android:text="@string/fa_android" android:textColor="#1fa67a" android:textSize="20sp" > </TextView> <TextView android:id="@+id/tab2" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:gravity="center" android:text="@string/fa_windows" android:textColor="#1fa67a" android:textSize="20sp" > </TextView> <TextView android:id="@+id/tab3" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:gravity="center" android:text="@string/fa_linux" android:textColor="#1fa67a" android:textSize="20sp" > </TextView> </LinearLayout> </LinearLayout>
然后为每个TextView设置字体
private void initView() {
Typeface font = Typeface.createFromAsset(getAssets(), "fontawesome-webfont.ttf");
tab1 = (TextView) findViewById(R.id.tab1);
tab2 = (TextView) findViewById(R.id.tab2);
tab3 = (TextView) findViewById(R.id.tab3);
tab1.setTypeface(font);
tab2.setTypeface(font);
tab3.setTypeface(font);
}
如果你想改变图标大小和颜色,只要修改字体的大小和颜色即可,也就是说只要修改TextView的textSize和textColor。
更多使用效果待你去发现。
源码下载
http://download.csdn.net/detail/sbsujjbcy/8567213
相关文章推荐
- element-ui中使用font-awesome字体图标
- wpf 使用Font-Awesome图标字体
- iconfont字体图标的使用方法--超简单! 我之前因为项目用bootstrap比较多,所以使用font awesome字体图标比较多,后来接触到了iconfont,发现想要的什么图标都有,还可以
- Android调用font-awesome字体图标
- 在android项目中使用FontAwesome字体
- android中使用iconfont图标字体
- RN(react native)入坑指南-05,使用图标字体Fontawesome
- [ExtJS5学习笔记]第五节 使用fontawesome给你的extjs5应用增加字体图标
- Android怎么使用字体图标 自定义FontTextView字体图标控件-- 使用方法
- 如何在Axure中使用FontAwesome字体图标
- Android iconfont字体图标的使用
- 学习WPF——使用Font-Awesome图标字体
- 如何在photoshop等图像编辑软件中使用Font Awesome字体图标
- [ExtJS5学习笔记]第五节 使用fontawesome给你的extjs5应用增加字体图标
- [ExtJS5学习笔记]第五节 使用fontawesome给你的extjs5应用增加字体图标
- 在SVG中使用Bootstrap或FontAwesome图标字体
- Android使用Font Awesome显示小图标
- android 使用字体图标(Icon Font)
- Android使用Font Awesome显示小图标(二)
- Axure中使用FontAwesome字体