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. bootstrap模态框modal使用remote第二次加载显示相同内容解决办法

    bootstrap模态框modal使用remote动态加载内容,第二次加载显示相同内容解决办法 bootstrap的modal中,使用remote可以动态加载页面到modal-body中,并弹窗显示 ...

  2. 如何定制Activity的标题栏

    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); setContentView(R.layout.main); //自定义标题栏        mW ...

  3. jquery实现手风琴效果

    html----accordion.html <!DOCTYPE html> <html lang="en"> <head> <meta ...

  4. 基于Chrome内核(WebKit.net)定制开发DoNet浏览器

    1.    源起 a)     定制.Net浏览器 本人是一名C#开发者,而作为C#开发者,做客户端应用中最头痛的一件事就是没有一个好的UI解决方案, WinFrom嘛,效率虽然还不错,但是做一些特殊 ...

  5. 使用Glyph Designer创建位图字体

     使用Glyph Designer创建位图字体 转http://book.2cto.com/201210/6610.html   <iOS 5 cocos2d游戏开发实战(第2版)>将引导 ...

  6. Access 2003下载地址和密钥

    电驴下载链接:ed2k://|file|sc_access_2003.iso|645523456|63AA6C30D609FDC22D056C4B424283F9|/ 安装SN: HH74C-P8F7 ...

  7. Android开机启动Activity或者Service方法

    本文出自 “Bill_Hoo专栏” 博客,请务必保留此出处http://billhoo.blog.51cto.com/2337751/761230 这段时间在做Android的基础开发,现在有一需求是 ...

  8. Spring Batch 中文参考文档 V3.0.6 - 1 Spring Batch介绍

    1 Spring Batch介绍 企业领域中许多应用系统需要采用批处理的方式在特定环境中运行业务操作任务.这种业务作业包括自动化,大量信息的复杂操作,他们不需要人工干预,并能高效运行.这些典型作业包括 ...

  9. hosts文件的一个小发现

    今天才发现原来同一个ip可以在hosts文件中配置多个域名.之间老是换一个网站就改一下,现在终于不用这么麻烦了 127.0.0.1 gg.pclady.com.cn 127.0.0.1 gg.pcon ...

  10. step by step设置postgresql用户密码并配置远程连接

    设置pgsql默认用户posgres的密码 1.确认pgsql是开启的 /etc/init.d/postgresql status 2.使用默认用户登录 sudo su postgres 3.进入ps ...