作者:201153蜡笔小新 | 来源:互联网 | 2024-11-12 12:07
前言:本文由编程笔记小编整理,旨在介绍如何在Android应用中使用IconFont来显示图标,从而减少应用的体积,希望对您有所帮助。
1、访问IconFont官网,选择需要的图标并加入购物车。
2、在购物车页面选择下载代码包。

3、解压下载的文件,将其中的四个文件(包括iconfont.ttf)放入项目的assets文件夹中。

4、在代码中通过设置TextView的TypeFace属性来加载和显示图标。
1 TextView testView = findViewById(R.id.text);
2 Typeface typeface = Typeface.createFromAsset(getAssets(), "iconfont.ttf");
3 testView.setTypeface(typeface);
4 testView.setText(Html.fromHtml("󰍃"));
<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:gravity="center"
android:textColor="#ffcc0000"
android:textSize="30sp" />