Android 使用Font Awesome 显示文字图标
2016-07-20 15:55
399 查看
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 Studio -修改LogCat的颜色
- Android:使用LeanCloud遇到的坑
- Android使用UncaughtExceptionHandler捕获全局异常
- android中libs目录下armeabi和armeabi-v7a的区别
- Android属性动画学习笔记(一)
- 安卓开发之Bitmap(二)
- Android 读写文件
- android 数据库的使用
- Attempt to invoke virtual method 'int android.view.View.getImportantForAccessibility()'解决方案
- 安卓学习笔记---Android引导蒙层
- Android Toast 使用小技巧
- Android中RecyclerView实现横向滑动代码
- ANDROID内存优化(大汇总——全)
- android:RecycleView的简单封装使用
- Intellij idea(pycharm,android studio)代码提示 设置不区分大小写
- 【项目中】关于android:windowNoTitle不起作用的解决办法
- Android RecyclerView详解之实现 ListView GridView瀑布流效果
- Android端应用秒开优化体验
- Android学习笔记033之数据存储—SharedPreference
- android studio修改工程包名