【问题标题】:Is it possible to clear the default font for certain TextView after setting default font globally using Calligraphy?在使用 Calligraphy 全局设置默认字体后,是否可以清除某些 TextView 的默认字体?
【发布时间】:2016-05-27 14:26:05
【问题描述】:

我已经在 onCreate() 方法中设置了我的应用程序类的默认字体,详见书法文档:

CalligraphyConfig.initDefault(new CalligraphyConfig.
        .setDefaultFontPath("fonts/MetaOT-Medi.otf")
        .setFontAttrId(R.attr.fontPath)
        .addCustomViewWithSetTypeface(CustomViewWithTypefaceSupport.class)
        .addCustomStyle(TextField.class, R.attr.textFieldStyle)
        .build()
);

我有一个 TextView,并希望它使用默认系统字体(例如 Roboto)回退。我可以知道怎么做吗?

现在我通过将一组 Roboto 字体复制到我的资产/字体文件夹来规避这个问题,然后对于那些我想回退的 TextView,覆盖字体以在 xml 中使用它,例如 fontPath="fonts/Roboto-Regular.ttf"。或者除此之外还有更好的解决方案吗?

【问题讨论】:

    标签: android fonts android-fonts


    【解决方案1】:

    是的,有可能,你想设置哪种字体TextView你可以用XML或务实地设置它。

     fontPath="fonts/Roboto-Regular.ttf"
    

    XML 示例代码

    <TextView
         android:id="@+id/tv_name"
            fontPath="fonts/Roboto-Regular.ttf"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
    />
    

    实用示例代码

    Typeface tf = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Regular.ttf");
            setTypeFace(view, tf);
    

    【讨论】:

    • 我现在正在使用这个解决方案(这需要我将一组 Roboto 字体复制到 assets/fonts 文件夹),但问题是我希望它像所描述的问题一样回退操作系统系统默认字体这里:github.com/chrisjenx/Calligraphy/issues/152
    • 使用另一个库,如 iconify
    猜你喜欢
    • 1970-01-01
    • 2022-11-19
    • 2012-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-14
    相关资源
    最近更新 更多