2016-03-01 47 views
0

中的世紀哥特式,所以字體有4種或5種字體樣式,如果我們需要其他字體樣式。我發現textappearance可以做到,但如何?如何將textfont更改爲android

+0

兄弟先做谷歌.. !!! – Nils

+2

你到底想要什麼? – Nils

+0

請在發佈之前嘗試搜索。 http://stackoverflow.com/questions/5634245/how-to-add-external-fonts-to-android-application – Rohit5k2

回答

1

創建一個文件夾資產文件夾下稱爲字體,並把所有的字體在裏面。 (文件夾名稱可以是任何東西)

activity_main.xml中

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    android:background="#222222" > 

    <TextView 
     android:id="@+id/ghost" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:textSize="70dip" 
     android:gravity="center" 
     android:textColor="#ef0000" 
     android:layout_marginTop="50dip" 
     android:text="ghost" /> 

</LinearLayout> 

SampleActivity.java

package com.example; 

import android.app.Activity; 
import android.graphics.Typeface; 
import android.os.Bundle; 
import android.widget.TextView; 

public class AndroidExternalFontsActivity extends Activity { 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     // Font path 
     String fontPath = "fonts/Face Your Fears.ttf"; 

     // text view label 
     TextView txtGhost = (TextView) findViewById(R.id.ghost); 

     // Loading Font Face 
     Typeface tf = Typeface.createFromAsset(getAssets(), fontPath); 

     // Applying font 
     txtGhost.setTypeface(tf); 
    } 
} 
0

首先創建資產文件夾,然後在資產文件夾中創建字體文件夾。

TypeFace customTypeFace=Typeface.createFromAsset(getAssets(),"fonts/mytruetypefont.ttf"); 
Textview.setTypeface(typeFace); 
相關問題