Calligraphy
Calligraphy copied to clipboard
Allow using theme attributes when setting fontPath on a TextView
We've started using theme attributes for our fonts like this:
<attr name="fontPathMedium" format="reference|string" />
<style name="Widget.TextView" parent="android:Widget.TextView">
<item name="fontPath">?fontPathMedium</item>
</style>
This works great but this does not:
<TextView
....
fontPath="?fontPathMedium" />
It seems the case where a string resource is used (@string/fontPathMedium) is handled but not attributes.
Interesting. This isn't high on my priority list, but feel free to have a fiddle around let me know what you find out.
This turned out trickier than expected.
Resources#obtainStyledAttributes will fetch from the AttributeSet, styles and themes which isn't relaly what we want here.
So the only other way I can think of is by checking if the string starts with ? and in that case look in the theme. I don't know how to resolve the string (?attributeName) to the value though.
I think someone else was doing something similar, I'll reach out and see if there is a better way at resolving attributes.
On Sat, 10 Oct 2015 10:20 Nicklas Ansman Giertz [email protected] wrote:
This turned out trickier than expected. Resources#obtainStyledAttributes will fetch from the AttributeSet, styles and themes which isn't relaly what we want here. So the only other way I can think of is by checking if the string starts with ? and in that case look in the theme. I don't know how to resolve the string (?attributeName) to the value though.
— Reply to this email directly or view it on GitHub https://github.com/chrisjenx/Calligraphy/issues/216#issuecomment-147068093 .
Out of curiosity, @ansman, is the attribute fontPathMedium included in the theme whose context the TextView is using?
Out of curiosity, @ansman, is the attribute fontPathMedium included in the theme whose context the TextView is using?
<style name="Theme.MyApp" parent="android:Theme">
<item name="fontPathMedium">"fonts/something_something.ttf"</>
</style>
@c-h-b they are defined in the theme