Android 使用Font Awesome 显示文字图标
Android 使用Font Awesome 显示文字图标
简单几步就可以完成
简单的效果图:

1. 创建 assets 文件夹
在Android Studio 上的创建步骤为:
在 src/main上右键 --> New --> Folder --> Assets Folder.
将FontAwesome 字体文件copy到assets指定的路径,这里我放在assets/font/fontawesome-webfont.ttf.
2. 编写资源文件与代码
/values/strings.xml
<string name="fa_car"></string>
<string name="fa_apple"></string>
<string name="fa_android"></string>
activity_layout.xml
//...
<TextView
android:id="@+id/tv_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/fa_car"
android:textSize="20sp"
android:textColor="@color/cardview_shadow_start_color"
/>
<TextView
android:id="@+id/tv_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/fa_apple"
android:textSize="24sp"
android:textColor="@color/colorPrimaryDark"
/>
<TextView
android:id="@+id/tv_3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/fa_android"
android:textSize="48sp"
android:textColor="@color/colorAccent"
/>
//...
Activity类
TextView tv_1 = (TextView)findViewById(R.id.tv_1);
TextView tv_2 = (TextView)findViewById(R.id.tv_2);
TextView tv_3 = (TextView)findViewById(R.id.tv_3);
//获取assets文件夹里的字体文件
Typeface font = Typeface.createFromAsset(getAssets(), "font/fontawesome-webfont.ttf");
//给指定的TextView加载字体
tv_1.setTypeface(font);
tv_2.setTypeface(font);
tv_3.setTypeface(font);
3. 最后附上字体下载链接
对照表:http://fontawesome.io/cheatsheet/
Android 使用Font Awesome 显示文字图标的更多相关文章
- Android的TextView在显示文字的时候,如果有段中文有英文,有中文,有中文标点符号,你会发现,当要换行的时候遇到中文标点, 这一行就会空出很多空格出来
一.问题描述: Android的TextView在显示文字的时候,如果有段中文有英文,有中文,有中文标点符号,你会发现,当要换行的时候遇到中文标点, 这一行就会空出很多空格出来.原因是: 1) Tex ...
- 解决TextView在显示文字的时候,一行还没显示满就跳到下一行
转载请注明:转自 http://blog.csdn.NET/u011176685/article/details/48295185 一.问题描述: Android的TextView在显示文字的时候,如 ...
- 动态更新Toolbar Menu以及Menu中同时显示文字和图标
动态更新Toolbar Menu以及Menu中同时显示文字和图标 我们经常会有这样的需求,在切换Fragment或者点击某个按钮后动态更新Toolbar上Menu项.但是onCreateOptions ...
- ActionBar只显示图标不显示文字
问题:ActionBar菜单项android:showAsAction设置为android:showAsAction="always|withText"或者android:show ...
- 使用 Android Studio 开发工具创建一个 Android 应用程序,显示一行文字“Hello Android”,并将应用程序的名称更改为“FirstApp”。
需求说明: 使用 Android Studio 开发工具创建一个 Android 应用程序,显示一行文字"Hello Android",并将应用程序的名称更改为"Firs ...
- android如何改变应用程序安装后显示的图标
修改 res目录下所有ic_launcher.png 为你想显示的图标
- 我的Android进阶之旅------>关于使用Android Studio替换App的launcher图标之后仍然显示默认的ic_launcher图标的解决方法
前言 最近做了一个App,之前开发该App的时候一直以来都是默认的launcher图标启动的, 今天美工换了一个App的launcher 图标,因此在Android Studio中将默认的lanche ...
- SDL显示文字
前面教程里,我们只显示图片,没提到如何显示文字, SDL本身没有显示文字功能,它需要用扩展库SDL_ttf来显示文字.ttf是True Type Font的缩写,ttf是Windows下的缺省字体,它 ...
- Android图形显示系统——上层显示1:界面绘制大纲
Android显示之应用界面绘制 越到上层,跟业务关联越直接.代码就越繁杂.Android上层显示的代码正是如此.此外,java语言本身繁复的特点(比C语言多了满屏的try-catch,比C++少了析 ...
随机推荐
- HDU Math Problems
1576 const int mod = 9973; n = a - a / mod * mod; a / b = ans; ans * b = a = a / mod * mod + n; n = ...
- 一种模拟position: sticky;的方法
直接上代码,本例采用了jQuery来进行介绍 CSS部分: .sticky { position: fixed; top: 0; } JS部分: var stickyBar = $('.sticky- ...
- linux环境下安装mongodb
最近有用到mongodb,顺便找到了以前的指南,顺便写一篇随笔,以后或许有用到的地方. 第一步:下载mongodb的linux版本,mongodb-linux-x86_64-3.2.4.tgz(去官网 ...
- 使用.net Reflector手动修改单个dll文件
在项目中修改bug会存才版本混乱的问题,加上dll中的依赖项目比较多,想要修改单个dll文件中的少量代码是很麻烦的. 可以使用Reflector和Reflexil可以手动修改单个dll文件,我使用的是 ...
- [原] XAF 如何啟用ListView橫向滾動條
using System; using DevExpress.ExpressApp; using DevExpress.ExpressApp.Win.Editors; using DevExpress ...
- Android中实现多彩的霓虹灯
1.布局文件 <?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:androi ...
- day14---html基础
本节内容: 一.HTML 二.CSS 三.JS HTML 1.一套规则,浏览器认识的规则. 2.开发者: 学习Html规则 开发后台程序: - 写Html文件(充当模板的作用) ****** - 数据 ...
- SecureCRT使用sz和rz命令进行文件的上传和下载
SecureCRT可以使用sz和rz命令进行文件的上传和下载. sz文件下载: 格式:sz 文件名称 即可将服务器的文件下载至本地. rz文件上传: 格式:rz 文件名称 即可将本地文件上传至服务器. ...
- Ubuntu NFSserver 简易安装及使用
服务器端(ip:192.168.1.100): sudo apt-get install nfs-kernel-server #安装nfs 客户端(ip:192.168.1.110): sudo ap ...
- MySql Windws 下自动备份脚本
这几天正在做一个 使用MySQL数据库的项目,目前项目已经完成了,当部署好项目之后,正在考虑如何自动备份MySql数据库的问题,我在网上找了一下资料终于解决了,特此记录一下. @echo off e ...