我在main.xml上使用 Layout Editor創建了一個textview名稱是textView1。
我想使用一個自定義的字體,所以我在onCreate方法中創建了下面的代碼,但是好像不能識別textView1。
package com.mystraldesign.memorable;
import android.app.Activity;
import android.graphics.Typeface;
import android.os.Bundle;
public class MemorableActivity extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Typeface type = Typeface.createFromAsset(getAssets(),"fonts/optima.ttf");
textView1.setTypeface(type);
}
}
什麼原因呢?
TextView textView1=(TextView)findViewById(R.id.textView1);//mail.xml裡這個textview的id
Typeface type = Typeface.createFromAsset(getAssets(),"fonts/optima.ttf");
textView1.setTypeface(type);