アプリケーション全体については、カスタムTextViewを作成する必要があります。xmlのすべてのtextviewについて、以下に示すように、この最初のmakeフォルダーに移動する前に、そのフォントフォルダー内のアセットにフォントの名前を付けてurfontstheiti.ttfを追加します。
import android.content.Context;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.widget.TextView;
public class MyTextView extends TextView{
public MyTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
public MyTextView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public MyTextView(Context context) {
super(context);
init();
}
private void init() {
if (!isInEditMode()) {
Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "fonts/stheiti.ttf");
setTypeface(tf);
}
}
}
その後、xml内のすべてのtextviewに対して、xml内のur textviewよりもこのタイプのフォントが必要な場合は、通常のtextviewと同じように必要なtextviewの他のプロパティを追加します。
<YourProjectPackageName.MyTextView
android:id="@+id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="22px"
android:textColor="#34A4c5"
></YourProjectPackageName>
アクティビティでは、以下に示すようにカスタムテキストビューを使用します
MyTextView textview=(MyTextView)findViewById(R.id.textview);