IconFont字體不僅僅流行語Web開發(fā),在移動(dòng)開發(fā)中也漸漸的使用的范圍更廣泛。這里介紹在Android開發(fā)中使用icon font的代碼和方法。
應(yīng)用步驟:
1、第一步:復(fù)制字體文件到項(xiàng)目 assets 目錄;
2、第二步:打開 iconfont 目錄中的 demo.html,找到圖標(biāo)相對應(yīng)的 HTML 實(shí)體字符碼;
3、第三步:打開 res/values/strings.xml,添加 string 值;
<string name="icons">㘅 㖭 㖮 㖯</string>
4、第四步:打開 activity_main.xml,添加 string 值到 TextView:
<TextView
android:id="@+id/like"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/icons" />
5、第五步:為 TextView 指定文字:
import android.graphics.Typeface;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Typeface iconfont = Typeface.createFromAsset(getAssets(), "iconfont/iconfont.ttf");
TextView textview = (TextView)findViewById(R.id.like);
textview.setTypeface(iconfont);
}