項目缺少ui,但是又需要很多icon,爲了和web的界面統一,android中,我也採用裏iconfont的方案。寫一個iconTextView繼承TextView
package com.edusohoapp.app.view;
import android.content.Context;
import android.graphics.Typeface;
import android.widget.TextView;
/**
* Created by suju on 14-5-12.
*/
public class EduSohoIconView extends TextView{
private Context mContext;
public EduSohoIconView(Context context) {
super(context);
mContext = context;
initView();
}
public EduSohoIconView(android.content.Context context, android.util.AttributeSet attrs) {
super(context, attrs);
mContext = context;
initView();
}
private void initView()
{
Typeface iconfont = Typeface.createFromAsset(mContext.getAssets(), "normal.ttf");
setTypeface(iconfont);
}
}
去網上選擇一個齊全一點的iconfont庫,然後下載ttf文件放到安卓的assets目錄中。“normal.ttf”是我這裏使用的字體名稱。
下載一個fontlab studio 可以查看font字體的unicode編碼,因爲在安卓中TextView 要使用unicode值。
如上圖,F002就是字體的unicode值。
這樣更改TextView的text值爲 就可以顯示自定義的font