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:onClick="onBack" 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"));
新闻热点
疑难解答