您的位置:首页 > 移动开发 > Android开发

Android:使用矢量图标(iconfont方式)

2017-02-09 15:12 573 查看
1.在阿里巴巴矢量图标库注册一个帐号,并创建项目加入自已的图标,下载文件包解压后取出iconfont.ttf文件放入

Android项目的assets文件夹下。

2.在string.xml文件中定义字符串,并将矢量图标对应的字符串粘贴进去。

<string name="icon_back">...</string>

3.在布局中使用TextView控件,并把文本设为string.xml文件中定义的字符串,可以像设置文字字体一样的方式改变图标

颜色。

<TextView
android:id="@+id/tv_set_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="15dp"
android:textColor="@color/theme_text_black"
android:text="@string/icon_back"
android:textSize="25dp" />

4.在代码中将TextView的字体样式改为iconfont.ttf。

TextView backTv = (TextView) findViewById(R.id.tv_set_back);
backTv.setTypeface(Typeface.createFromAsset(getAssets(), "iconfont.ttf"));

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: