1

我想在我的 android 应用程序中为所有视图使用 Roboto 字体,我该怎么做?

4

2 回答 2

1

创建自定义视图,例如 TextView、EditText 等。然后在构造函数中设置下面的 setTypeface 示例:

public class RobotoTextView extends TextView {

    public RobotoTextView(Context context) {
        super(context);
        setTypeface(Typeface
                .createFromAsset(context.getAssets(), "fontname.ttf"));

    }
}

然后在你的布局中使用它,而不是使用标准的 TextView 使用下面的自定义类示例:

<packagename.RobotoTextView
            style="@style/usecustomstyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/yourid"/>
于 2013-02-01T16:09:54.743 回答
0

使用字体。将您的字体文件放在 assest 文件夹中。然后写下面的代码。

 Typeface Roboto = Typeface.createFromAsset(getAssets(), "Roboto.ttf"); 

然后使用 Roboto 字体所有你的TextViewEditText..etc

  Textview.setTypeface(italic);  
于 2013-02-01T16:08:28.103 回答