我的应用程序中有一个 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);
有什么想法吗?
最佳答案
您可以使用以下方式获取默认字体:
if (keep_curren) {
font_title = Typeface.DEFAULT;
}
您还可以根据指定样式获取默认字体:Typeface.defaultFromStyle(int style)
。
更多相关信息:Here .
关于android - 如何获取Android设备的默认字体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18293915/