开发者

How can I set the font of a textView in Android?

I'm trying to set the font to a custom font. the font is in a subfolder of the assets folder called "fonts" . This is code in my onCreate() function. Eclipse suddendly brings up the debugger saying "source not found"

    Typeface centuryGothic = Typeface.createFromAsset(this.getAssets(), "fonts/Century_Gothic_Bold.ttf");
    TextView tv = (TextView) findViewById(R.id.TitleAct_title);
    tv.setTypeface(centuryGothic);
    setContentView(tv);
开发者_如何学Python

This is the xml in My main at the moment

<?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>

I can't see anything wrong with this. Why is it bringing up the debugger and error "source not found"?


What you saw was the eclipse debugger looking for the source of the exception. next time, press continue and look ad the log of the exception in the Logcat window.

You should call setContentView(R.layout.main); before TextView tv = (TextView) findViewById(R.id.TitleAct_title);, and probably drop the call setContentView(tv);.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜