This question already has answers here:
Roboto font in my android app
                                
                                    (3个答案)
                                
                        
                                5年前关闭。
            
                    
我想对我的android应用程序中的所有视图使用Roboto字体,该怎么办?

最佳答案

创建自定义视图,例如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"/>

07-24 09:49
查看更多