【问题标题】:Font not changing字体不变
【发布时间】:2011-11-02 18:33:05
【问题描述】:

我有一个问题..我使用了不同的字体,实际上只有 1 个按钮显示了具有该字体的文本... 只有继续按钮实际上显示了正确的字体!! 我会给出代码,因为我试图修复它,但我失败了......也许你可以修复它:

 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>

【问题讨论】:

    标签: android xml text button fonts


    【解决方案1】:

    您一直在使用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);
    

    【讨论】:

    • 大声笑我不敢相信...我的朋友是编码 7 小时的结果...:) 对不起这个愚蠢的问题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-14
    • 2021-06-30
    • 2013-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多