Google Maps Developers Live: Google Maps Android API V2
2013年1月30日星期三
2013年1月3日星期四
在Android上顯示TTF/OTF
"OTF" 是 OpenType 字體, 在大多數現代操作系統中使用.
"TTF" 是 TrueType 字體, 適用於Windows的首選.
要在Android上顯示TTF/OTF, 首先要下載和複製到/assets/fonts 文件夾. 可以在這裡找到一些免費的字體. 注意, 僅複製所需要的字體文件, 否則,很浪費內存資源, 甚至不能加載/運行!
程序代碼:
"TTF" 是 TrueType 字體, 適用於Windows的首選.
要在Android上顯示TTF/OTF, 首先要下載和複製到/assets/fonts 文件夾. 可以在這裡找到一些免費的字體. 注意, 僅複製所需要的字體文件, 否則,很浪費內存資源, 甚至不能加載/運行!
程序代碼:
package com.example.androidfonts;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.Typeface;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView ttfView = (TextView)findViewById(R.id.ttf);
TextView otfView = (TextView)findViewById(R.id.otf);
Typeface ttfFace_FreeMonoBold = Typeface.createFromAsset(getAssets(),
"fonts/FreeMonoBold.ttf");
Typeface otfFace_FreeSansBoldOblique = Typeface.createFromAsset(getAssets(),
"fonts/FreeSansBoldOblique.otf");
ttfView.setTypeface(ttfFace_FreeMonoBold);
ttfView.setTextSize(28);
otfView.setTypeface(otfFace_FreeSansBoldOblique);
otfView.setTextSize(28);
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<TextView
android:id="@+id/ttf"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello! I'm TTF" />
<TextView
android:id="@+id/otf"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello! I'm OTF" />
</LinearLayout>
訂閱:
留言 (Atom)

