Android : Use custom font in style attribute

on Wednesday, September 10, 2014


What I want to achieve is adding style attribute to my axml file with custom font loaded from Asset.


I know I can load built-in fontface like this (style.xml):



<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CodeFont" parent="@android:style/TextAppearance.Medium">
<item name="android:typeface">monospace</item>
</style>
</resources>


And use it (Main.axml):



<TextView
style="@style/CodeFont"
local:MvxBind="Text Hello" />


I know that I can also create MyCustomTextView extending TextView and setting font by SetTypeface method, but I would like to use custom font in style attribute.


So something like:



<resources>
<style name="CodeFont" parent="@android:style/TextAppearance.Medium">
<item name="android:typeface">MyCustomFontLoadedFromAsset</item>
</style>
</resources>


Is it possible?


0 comments:

Post a Comment