从阿里云的Iconfont.cn下载图标字体。

解压缩后,可以找到 iconfont.ttf 文件。
在android项目下创建 assets 资源文件夹。

将 iconfont.ttf 文件拷贝到该文件夹下。
设置 TextView的 typeface 指向到该文件即可。
fun setTypeFont1(iconfontPath:String ) {
val assets: AssetManager = this.rootView.context.assets
val font1 = Typeface.createFromAsset(assets, iconfontPath)
this.setTypeface(font1)
}
然后,在 string.xml 文件中配置图标文字。
<string name="iconfont_hangqing"></string>
<string name="iconfont_paihang"></string>
<string name="iconfont_zixun"></string>
<string name="iconfont_wode"></string>
最后设置 TextView标签:
<TextView
android:id="@+id/bottom_menu_item_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:text="@string/iconfont_hangqing"
android:textColor="@color/white"
android:textSize="22dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
>
</TextView>
一切OK了。
本文介绍了如何在Android项目中集成阿里云Iconfont图标字体库。首先下载ttf文件,然后将其放入assets文件夹。接着设置TextView的typeface属性引用此字体文件,并在string.xml中使用特定字符编码来显示图标。最后通过示例展示了如何在布局文件中应用这些图标。
1002

被折叠的 条评论
为什么被折叠?



