android 6.0 出厂字体,如何获取Android设备的默认字体?

这篇博客讨论了如何在Android应用程序中根据用户选择动态切换系统默认字体和自定义字体。开发者创建了一个API类,其中包含一个静态变量用于存储字体。在API类的构造函数中,通过条件判断来决定设置字体。如果用户希望保留系统默认样式,则从系统获取Typeface,否则从assets目录加载自定义字体。在活动中,可以通过调用API类的变量来改变TextView的字体。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Jack K Fouani

12

fonts

android

我的应用程序中有一个API类; 例如,在API类中,有一个自定义字体已设置为静态

public static Typeface font_short;

@SuppressWarnings("deprecation")

public Api(Context c , Display d)

{

this.context = c ;

//I want to change this if user wants to keep using System font style or my custom style

if ( keep_curren == true )

{

font_title = //What to add here to get Default fonts Typeface

}else

//use my costume font

{

font_title = Typeface.createFromAsset(context.getAssets(),"fonts/custome.ttf");

}

display = d;

w = display.getWidth(); // deprecated

h = display.getHeight(); // deprecated

}

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

在活动类中

TextView blaaa = (TextView) findViewById(R.id.blaaa);

//change to custome font style or keep current font style

blaaa.setTypeface(Api.font_title);

有任何想法吗?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值