[英]How can I set the font of a textView in Android?
我正在嘗試將字體設置為自定義字體。 該字體位於資源文件夾的子文件夾中,稱為“ fonts”。 這是我的onCreate()函數中的代碼。 Eclipse突然打開調試器,提示“找不到源”
Typeface centuryGothic = Typeface.createFromAsset(this.getAssets(), "fonts/Century_Gothic_Bold.ttf");
TextView tv = (TextView) findViewById(R.id.TitleAct_title);
tv.setTypeface(centuryGothic);
setContentView(tv);
這是目前我主要的xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<TextView
android:text="@string/TitleAct_title"
android:id="@+id/TitleAct_title"
android:textColor="#fff"
android:gravity="center_horizontal"
android:background="#347"
android:textSize="15pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
我看不出有什么問題。 為什么顯示調試器和錯誤“找不到源”?
您看到的是Eclipse調試器在尋找異常的來源。 下次,請按繼續,然后在Logcat窗口中查看異常日志。
您應該調用setContentView(R.layout.main);
在TextView tv = (TextView) findViewById(R.id.TitleAct_title);
,並且可能會放棄調用setContentView(tv);
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.