gpt4 book ai didi

android - 使用自定义字体的最简单方法? - 安卓

转载 作者:数据小太阳 更新时间:2023-10-29 02:41:54 26 4
gpt4 key购买 nike

我发现在我的 android 应用程序上使用自定义字体的方法是使用下面的代码

TextView txt = (TextView) findViewById(R.id.textView1);  
Typeface font = Typeface.createFromAsset(getAssets(), "ABCD.TTF");
txt.setTypeface(font);

我已将 ABCD.TTF 存储在 assets 文件夹中..

是的,它可以工作,没有任何问题。问题是我必须为我拥有的每一个文本、按钮等添加上面的代码。如果有很多文本和各种 Activity 中的按钮:(

我需要的是一种替代方法,一种最简单的方法..

就像使用像上面那样不重复的单个代码块来更改所有内容的字体..

否则在 xml

中执行

或者有什么方法可以将我们的自定义字体添加到存在 normal,sans,serif,monospace 的内置字体中。

最佳答案

like using a single block of code not repeatative like the above to change the fonts for all the stuffs..

在各种 StackOverflow 答案中已经解决了一些执行此操作的方法。这是迭代 ViewGroup 的子项并将 Typeface 应用于所有实现 TextView 的子项:
- https://stackoverflow.com/a/7580370/115145

else doing it in the xml

抱歉,不支持。

or is there any way to add our custom font to the inbuilt typeface where normal,sans,serif,monospace are present.

抱歉,不支持,除非您构建自己的固件。

关于android - 使用自定义字体的最简单方法? - 安卓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11072644/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com