【问题标题】:Initialize Typeface in a fragment在片段中初始化字体
【发布时间】:2013-10-29 08:32:24
【问题描述】:

我有这条线:

Typeface font = Typeface.createFromAsset(getAssets(), "fonts/Delius-Regular.ttf");

但是getAssets() 参数似乎会带来一些错误,它带有可怕的红线下划线,它说

没有为 ProfileFragment 类型定义方法 getAssets()

ProfileFragment 是我的类的名称,它扩展了 Fragment。

注意:字体样式也在 assets 文件夹中。

【问题讨论】:

  • getActivity().getAssets()
  • 你试过getActivitiy().getAssets()....
  • tnx 成功了,我在这里学到了很多哈哈..

标签: android android-fragments fragment typeface


【解决方案1】:

您不能直接从片段中获取getAssets()。您必须使用getActivity().getAssets() 而不是仅使用getAssets()


使用这个

Typeface font = Typeface.createFromAsset(getActivity().getAssets(), "fonts/Delius-Regular.ttf");

而不是

Typeface font = Typeface.createFromAsset(getAssets(), "fonts/Delius-Regular.ttf");

阅读更多关于Set custom font for Android fragments

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-16
    • 2020-12-26
    • 1970-01-01
    • 1970-01-01
    • 2018-10-22
    • 2022-08-23
    • 2020-11-26
    • 2010-12-27
    相关资源
    最近更新 更多