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. webform 之LINQde 简单操作

    LinQ: LinQ to Sql类它是一个集成化的数据访问类,微软将原本需要我们自己动手去编写的一些代码,集成到了这个类中,会自动生成. 数据库数据访问,能大大减少代码量. 那就是代码量减少 EF框 ...

  2. SQL Server简洁查询正在运行的进程SQL

    通常我们可以使用 sp_who2 我们希望更加简洁的信息,下面这个查询使用系统表sys.sysprocesses,以及sys.dm_exec_sql_text做OUTER APPLY. T-SQL是这 ...

  3. Ubuntu搭建Ruby on Rails环境

    安装Ruby 由于Ubuntu的apt包管理器的ruby版本过旧,故考虑从源码编译安装.这里以安装ruby2.3.0为例: sudo apt-get install build-essential z ...

  4. Eclipse创建Android模拟器创建选项解释

  5. vb小菜一枚--------早期绑定和后期绑定

    早期绑定和后期绑定 Visual Studio 2005   其他版本   将对象分配给对象变量时,Visual Basic 编译器会执行一个名为 binding 的进程.如果将对象分配给声明为特定对 ...

  6. Python学习之路--select解析

    sellect.poll.epoll三者的区别 select select最早于1983年出现在4.2BSD中,它通过一个select()系统调用来监视多个文件描述符的数组,当select()返回后, ...

  7. MyEclipse10优化

    Myeclipse10 优化设置 一.myeclipse字体设置 Window->Preferences->General->Appearance->Colors and Fo ...

  8. 页面加载完成后加载多个函数的js完美解决方案

    function addLoadEvent(func) { var oldonload = window.onload; if (typeof window.onload != 'function') ...

  9. Yaf零基础学习总结4-Yaf的配置文件

    在上一节的hello yaf当中我们已经接触过了yaf的配置文件了, Yaf和用户共用一个配置空间, 也就是在Yaf_Application初始化时刻给出的配置文件中的配置. 作为区别, Yaf的配置 ...

  10. OpenCv编程

    (1)用OpenCv加载.显示.保存图片: //加载图片 IplImage* m_img;//定义IplImage格式的图片头指针: m_img=cvLoadImage(m_imgLoc);//装载m ...