項目缺少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