Android 使用Font Awesome 显示文字图标
2017-03-21 18:05
597 查看
简单几步就可以完成
简单的效果图:
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);
相关文章推荐
- Android 使用Font Awesome 显示文字图标
- Android基础教程(一)之------更改与显示文字标签TextView标签的使用
- 使用HZK16字库文件提取文字并显示到OLED显示屏上(Java Android实现)
- Android自定义ProgressBar,内部显示图标和文字,文字被进度条覆盖时会变色
- 我的Android进阶之旅------>关于使用Android Studio替换App的launcher图标之后仍然显示默认的ic_launcher图标的解决方法
- Android 中menu同时显示图标和文字的实现
- 3.1 MonoForAndroid用户人机界面-更改与显示文字标签-TextView标签的使用
- [Android] TextView上同时显示图标和文字
- android使用font awesome替代简单的图标
- Android开发—利用FrameLayout实现图标中间显示文字
- Android使用Font Awesome显示小图标
- Android TextView与html的结合使用 一个控件显示多种文字
- Android中使用Spinner来实现图标文字并存的二级联动
- Android基础教程(一)之------更改与显示文字标签TextView标签的使用
- android使用font awesome替代简单的图标
- android使用zxing扫描界面全是白色以及更改显示文字屏幕居中
- Android 使用TabHost 无法显示图标
- android不使用推送,在桌面图标上显示消息数量
- Android基础教程(一)之------更改与显示文字标签TextView标签的使用
- Android基础教程(一)之------更改与显示文字标签TextView标签的使用