如何获取Android设备的默认字体?

15

我的应用程序中有一个Api类。在Api类内部,有一个已经设置为静态的自定义字体。例如:

public static Typeface fontShort;

public Api(Context c, Display d) {
    // I want to change this if user wants to keep using system font style or my custom style
    if (shouldKeepCurrent == true) {
        // Use system default font
        fontTitle =  // ???
    } else {
        // Use my costume font
        fontTitle = Typeface.createFromAsset(context.getAssets(), "fonts/custom.ttf");
    }       
}

如果用户不想使用我的自定义字体,我希望能够获取设备的默认字体和当前字体!

在 Activity 类中:

TextView myView = (TextView) findViewById(R.id.myView);
// Change to custom font style or keep current font style
myView.setTypeface(Api.fontTitle);

有什么想法吗?

1个回答

41

您可以使用以下代码获取默认字体:

if (keep_curren) {
    font_title = Typeface.DEFAULT;
}

您还可以根据指定的样式获取默认字体: Typeface.defaultFromStyle(int style)

更多相关信息请参阅:这里


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接