Calligraphy icon indicating copy to clipboard operation
Calligraphy copied to clipboard

Allow using theme attributes when setting fontPath on a TextView

Open ansman opened this issue 10 years ago • 6 comments
trafficstars

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.

ansman avatar Oct 08 '15 08:10 ansman

Interesting. This isn't high on my priority list, but feel free to have a fiddle around let me know what you find out.

chrisjenx avatar Oct 09 '15 14:10 chrisjenx

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.

ansman avatar Oct 10 '15 09:10 ansman

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 .

chrisjenx avatar Oct 10 '15 09:10 chrisjenx

Out of curiosity, @ansman, is the attribute fontPathMedium included in the theme whose context the TextView is using?

c-b-h avatar May 14 '16 17:05 c-b-h

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-b-h avatar May 14 '16 17:05 c-b-h

@c-h-b they are defined in the theme

ansman avatar May 14 '16 19:05 ansman