[アンドロイド] Androidの内のテキストのフォントを作成します。

まず第一に、我々はファイル形式を持っている必要があり、フォントフォルダにコピーします 資産
その後、我々は* .javaファイルを使用 Typeface.createFromAsset テキストのフォントを設定する.

例えば、TextViewのためのフォントを設定:
ファイル* .xmlファイル

アンドロイド内のフォント

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".Font" >
 
    <TextView
        android:id="@+id/myFont"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="35dp"
        android:text="nguyenvanquan7826"
        android:textColor="#ff0000"
        android:textSize="23sp" />
 
</RelativeLayout>

ファイル*の.java

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
package VSNet.Test;
 
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 font = (TextView) findViewById(R.id.myFont);
        Typeface myTypeface = Typeface.createFromAsset(getAssets(), "fonts/VALLERGO.otf"); // dat fonts
        font.setTypeface(myTypeface);//kich hoat fonts
    }
}

結果 :

フォントのアンドロイド

ファイルのダウンロードデモ: Android_Fonts