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/

对照表:http://fontawesome.io/cheatsheet/

Android 使用Font Awesome 显示文字图标的更多相关文章

  1. Android的TextView在显示文字的时候,如果有段中文有英文,有中文,有中文标点符号,你会发现,当要换行的时候遇到中文标点, 这一行就会空出很多空格出来

    一.问题描述: Android的TextView在显示文字的时候,如果有段中文有英文,有中文,有中文标点符号,你会发现,当要换行的时候遇到中文标点, 这一行就会空出很多空格出来.原因是: 1) Tex ...

  2. 解决TextView在显示文字的时候,一行还没显示满就跳到下一行

    转载请注明:转自 http://blog.csdn.NET/u011176685/article/details/48295185 一.问题描述: Android的TextView在显示文字的时候,如 ...

  3. 动态更新Toolbar Menu以及Menu中同时显示文字和图标

    动态更新Toolbar Menu以及Menu中同时显示文字和图标 我们经常会有这样的需求,在切换Fragment或者点击某个按钮后动态更新Toolbar上Menu项.但是onCreateOptions ...

  4. ActionBar只显示图标不显示文字

    问题:ActionBar菜单项android:showAsAction设置为android:showAsAction="always|withText"或者android:show ...

  5. 使用 Android Studio 开发工具创建一个 Android 应用程序,显示一行文字“Hello Android”,并将应用程序的名称更改为“FirstApp”。

    需求说明: 使用 Android Studio 开发工具创建一个 Android 应用程序,显示一行文字"Hello Android",并将应用程序的名称更改为"Firs ...

  6. android如何改变应用程序安装后显示的图标

    修改 res目录下所有ic_launcher.png 为你想显示的图标

  7. 我的Android进阶之旅------>关于使用Android Studio替换App的launcher图标之后仍然显示默认的ic_launcher图标的解决方法

    前言 最近做了一个App,之前开发该App的时候一直以来都是默认的launcher图标启动的, 今天美工换了一个App的launcher 图标,因此在Android Studio中将默认的lanche ...

  8. SDL显示文字

    前面教程里,我们只显示图片,没提到如何显示文字, SDL本身没有显示文字功能,它需要用扩展库SDL_ttf来显示文字.ttf是True Type Font的缩写,ttf是Windows下的缺省字体,它 ...

  9. Android图形显示系统——上层显示1:界面绘制大纲

    Android显示之应用界面绘制 越到上层,跟业务关联越直接.代码就越繁杂.Android上层显示的代码正是如此.此外,java语言本身繁复的特点(比C语言多了满屏的try-catch,比C++少了析 ...

随机推荐

  1. 【转】webGL与OpenGL的不同

    原链接 http://www.khronos.org/webgl/wiki/WebGL_and_OpenGL_Differences WebGL and OpenGL Differences     ...

  2. mvc局部视图

    新建一个控制器啊! public ActionResult Index() { ViewBag.title = "this is title!!!"; return View(); ...

  3. g++编译选项

    -g,生成供调试用的可执行文件,可以在gdb中运行.由于文件中包含了调试信息因此运行效率很低,且文件也大不少. -c:生成名为source_file.o的目标文件. -o, 指定输出文件名,可以配合以 ...

  4. Sprint评审会议不是Sprint演示会议

    最近,Innolution公司的执行总监.Essential Scrum的作者Ken Rubin在其公司博客上撰写了一篇题为It’s a Sprint Review Not a Sprint Demo ...

  5. 我看见的第一个XCODE编译错误 - Command /applications.../clang failed with exit code 1

    开始用XCODE学习Apple相关开发的东东,写些demo熟悉Object C,一直还没看见什么问题,昨晚在家把一些demo上传到代码服务器,今天在另外一台机器上下载下来编译,出现了问题: Preco ...

  6. BNUOJ 51279[组队活动 Large](cdq分治+FFT)

    传送门 大意:ACM校队一共有n名队员,从1到n标号,现在n名队员要组成若干支队伍,每支队伍至多有m名队员,求一共有多少种不同的组队方案.两个组队方案被视为不同的,当且仅当存在至少一名队员在两种方案中 ...

  7. How to create Web Deployment Package and install the package

    Create Web Deployment Package To configure settings on the Connection tab In the Publish method drop ...

  8. vb- ----之常用函数

    [VB]常用函数 2007-10-25 10:52 3375人阅读 评论(1) 收藏 举报 vbstringdateintegervbscriptwindows (一)类型转换类函数1. CType( ...

  9. mono 开发

    引用 segmentfault.com/a/1190000002449629 配置 ASP.NET Linux( CentOS 6.5 ) 运行环境 MONO + Jexus me15000 179 ...

  10. 深入探究 WinRT 和 await

    在最近发布的使用 Windows 运行时中异步性来始终保持应用程序能够快速流畅地运行这篇博文中,包含了一些如何在 C# 和 Visual Basic 中使用 await 关键字的示例,允许开发人员在使 ...