在Android中使用icon图标

下载ttf文件

进入iconfont.cn,并登录选择自己要的icon图标

选择添加入库,点击自己的库

android icon 裁剪 android使用icon图标_java

选择下载代码

android icon 裁剪 android使用icon图标_java_02

引用

  1. 新建Assets文件夹

android icon 裁剪 android使用icon图标_加载_03

  1. 将下载的iconfont.ttf放入assets文件夹中

android icon 裁剪 android使用icon图标_java_04

  1. 打开demo_index.html,下拉找到字体编码

android icon 裁剪 android使用icon图标_ico_05

  1. 打开strings.xml添加一对标签,name自己取,后面的值为字体编码,也可随便写

android icon 裁剪 android使用icon图标_java_06


5. 建个TextView,text属性为刚才的值

android icon 裁剪 android使用icon图标_java_07

  1. 回到相关Activity,加载字体文件
public class IndexActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.index_main);

        // 加载字体文件
        Typeface iconfont = Typeface.createFromAsset(getAssets(), "iconfont.ttf");
        // 获取 textview 实例
        TextView textview = (TextView)findViewById(.icon_call);
        // 设置 typeface, 就是字体文件
        textview.setTypeface(iconfont);

    }
}
  1. 主要为以下代码
// 加载字体文件
        Typeface iconfont = Typeface.createFromAsset(getAssets(), "iconfont.ttf");
        // 获取 textview 实例
        TextView textview = (TextView)findViewById(.icon_call);
        // 设置 typeface, 就是字体文件
        textview.setTypeface(iconfont);