chrisjenx / Calligraphy

Custom fonts in Android the easy way...
Apache License 2.0
8.59k stars 1.1k forks source link

How to turn off Calligraphy for a specific style/textAppearance/view? #379

Open TWiStErRob opened 7 years ago

TWiStErRob commented 7 years ago

The current resolution path doesn't allow for exceptions. If I define the font in the theme to get it across the app, it's not possible to disable it on lower levels (textAppearance, style, view).

<style name="MyTextAppearance" parent="TextAppearance.AppCompat">
    ... other customizations
    <item name="fontPath">fonts/MyFont.ttf</item>
</style>

Which is used in the theme (as shown in https://github.com/chrisjenx/Calligraphy/issues/319#issuecomment-293930302).

I want to be able to say:

<style name="MyTextAppearance.NoCustomFont">
    <item name="fontPath">@null</item>
</style>

<TextView
        android:textAppearance="@style/MyTextAppearance.NoCustomFont"
    />

but this obviously doesn't work, because CalligraphyFactory is using TextUtils.isEmpty to check and fall back to more and more global values.

Would it be possible to include some magic value like fontPath="android:font-family" to break out of font resolution in onViewCreatedInternal and prevent calling applyFontToTextView?

OsmanYalin commented 5 years ago

yangjieK gave the trick:

https://github.com/chrisjenx/Calligraphy/issues/388#issuecomment-307311701