android textview svg,Android中使用SVG与WebFont矢量图标

一.参考文献

二.html使用方法

1.下载字体

网上百度自己要使用的字体,一般下载的是ttf格式,需要4种(或5)格式,其他的格式可以通过在线工具基于ttf转换

web-fontmin(这个在线转换工具更好用,注意,左边编辑框里的字全删除再上传ttf,不然只会转换框里的那些字体)

在线格式转换点此(注:该网站我成功转过,有时候会报错,多试几次)

2.css加载

@font-face {

font-family: "李旭科书法";

src: url("../font/李旭科书法.eot"); /* IE9 */

src: url("../font/李旭科书法.eot?#iefix") format("embedded-opentype"), /* IE6-IE8 */

url("../font/李旭科书法.woff") format("woff"), /* chrome, firefox */

url("../font/李旭科书法.ttf") format("truetype"), /* chrome, firefox, opera, Safari, Android, iOS 4.2+ */

url("../font/李旭科书法.svg#李旭科书法") format("svg"); /* iOS 4.1- */

font-style: normal;

font-weight: normal;

}

3.使用:在需要使用该字体的地方用即可:

.class{

font-family:'李旭科书法'

}

三、Android使用方法

3.1、下载fontawesome-webfont.ttf文件到assets文件中。

下载地址:http://fontawesome.io/#modal-download

如图所示:

9134b3d29a2e99f0ee5821c4c0af4bb7.png 

3.2、在values/strings.xml文件中(或者新建一个fonts.xml文件),定义资源,查看地址:http://fontawesome.io/cheatsheet/

3.3、使用一个照相机的图标来举一个例子

1.在布局文件中定义一个TextView:

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context="com.weather.MainActivity">

android:id="@+id/text_view"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/fa_camera" />

package com.weather;

import android.graphics.Typeface;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

TextView textView;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

Typeface font = Typeface.createFromAsset(getAssets(),"fontawesome-webfont.ttf");

textView= (TextView) findViewById(R.id.text_view);

textView.setTypeface(font);

}

}

参考文章

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值