字体不变

时间:2011-11-02 18:33:06

标签: android xml text button fonts

我有问题。我使用不同的字体,只有1个按钮实际显示带有该字体的文字... 只有continue按钮实际显示正确的字体! 我会给出代码,因为我试图解决它,但我失败了......也许你可以解决它:

 Typeface tf = Typeface.createFromAsset(getAssets(),
                "fonts/TYPOGRAPH PRO Ultra Light.ttf");

        TextView tv = (TextView) findViewById(R.id.continuebutton);
        tv.setTypeface(tf);


        TextView tv2 = (TextView) findViewById(R.id.newgame);
        tv.setTypeface(tf);

        TextView tv3 = (TextView) findViewById(R.id.aboutbutton);
        tv.setTypeface(tf);

        TextView tv4 = (TextView) findViewById(R.id.exit);
        tv.setTypeface(tf);

和xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="30dip" android:background="@drawable/pickip">


    <LinearLayout
    android:orientation="vertical"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:layout_gravity="center">



<Button

     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:text="Continue"
     android:id="@+id/continuebutton"
     android:background="@android:color/transparent"
     android:textColor="@android:color/white"
     android:textSize="32dp"
      />
<Button
android:id="@+id/newgame"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="New Game"
android:background="@android:color/transparent"
android:textColor="@android:color/white"
android:textSize="32dp"
/>
<Button
android:id="@+id/aboutbutton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="About"
android:background="@android:color/transparent"
android:textColor="@android:color/white"
android:textSize="32dp"
/>
<Button
android:id="@+id/exit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Exit"
android:background="@android:color/transparent"
android:textColor="@android:color/white"
android:textSize="32dp"
/>

     </LinearLayout>
</LinearLayout>

1 个答案:

答案 0 :(得分:3)

您始终使用tv.setTypface ...您必须将其更改为tv2tv3等。

    TextView tv = (TextView) findViewById(R.id.continuebutton);
    tv.setTypeface(tf);


    TextView tv2 = (TextView) findViewById(R.id.newgame);
    tv2.setTypeface(tf);

    TextView tv3 = (TextView) findViewById(R.id.aboutbutton);
    tv3.setTypeface(tf);

    TextView tv4 = (TextView) findViewById(R.id.exit);
    tv4.setTypeface(tf);