바로 외부 폰트를 적용하는거다. 안드로이드에서 자체 제공해주는 폰트는...monospace, sans serif, serif 요거 세개뿐...
거기다 저 3개는 거의 그게 그거다...그러다 Asset을 이용해 외부 폰트를 적용하는 방법은 찾았다.
public class StartAndroid extends Activity {
Typeface mFont;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
MyView vw = new MyView(this);
setContentView(vw);
mFont = Typeface.createFromAsset(getAssets(), "JustMeAgainDownHere.ttf");
}
protected class MyView extends View {
public MyView(Context context) {
super(context);
}
public void onDraw(Canvas canvas) {
Paint paint = new Paint();
canvas.drawColor(Color.WHITE);
String str = "Custom Font Test";
paint.setAntiAlias(true);
paint.setTypeface(mFont);
paint.setTextSize(30);
canvas.drawText(str, 10, 40, paint);
}
}
}
저 JustMeagainDownHere.ttf 파일은 구글링을 통해 얻었다. 저 파일을 다운로드해서 assets폴더에 넣은 후 getAssets()를 이용해서
폰트 적용을 할 수 있었다. 제법 깔쌈하네!
오~~~된다된다^^Paint랑 TextView랑 똑같네.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Custom Font Test" />
</LinearLayout>
public class StartAndroid extends Activity {
Typeface mFont;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mFont = Typeface.createFromAsset(getAssets(), "JustMeAgainDownHere.ttf");
TextView textView = (TextView)findViewById(R.id.textview);
textView.setTypeface(mFont);
textView.setTextSize(30);
}
}