Calligraphy
Calligraphy copied to clipboard
Setting custom font not working
I am trying to use this library for last 2 days but no luck. I believe I followed every step in guide lines.
I am using compile 'uk.co.chrisjenx:calligraphy:2.1.0'
Within Application onCreate I have, CalligraphyConfig.initDefault(new CalligraphyConfig.Builder() .setDefaultFontPath("fonts/Roboto-Italic.ttf") .setFontAttrId(R.attr.fontPath) .build() );
I have only one activity and others are all fragments. So in main activity I have added @Override protected void attachBaseContext(Context newBase) { super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase)); }
Now in styles.xml I have
and,
<style name="TextAppearance.FontPath" parent="android:TextAppearance">
<!-- Custom Attr-->
<item name="fontPath">fonts/Roboto-Italic.ttf</item>
</style>
None of this is changing the font for text views. Whats going wrong on my side?
Thanks.
What does <item name="android:textViewStyle">@style/AppTheme.TextAppearance</item>
inherit from?
Do you ever apply TextAppearance.FontPath
to any TextView
?
Yes, I have applied TextAppearance.FontPath but no effect. FOr more clarity i am including my full styles.xml file here. Please let me know if I am missing something,
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:windowActionBarOverlay">true</item>
<!--To change the text styling of options menu items</item>-->
<item name="android:itemTextAppearance">@style/MyActionBar.MenuTextStyle</item>
<!--To change the background of options menu-->
<item name="android:itemBackground">@color/appColor</item>
<item name="android:textColorPrimary">@color/Black</item>
<item name="colorAccent">@color/appColor</item>
<item name="android:textViewStyle">@style/AppTheme.TextAppearance</item>
</style>
<style name="AppTheme.TextAppearance" parent="android:Widget.TextView">
<item name="android:textStyle">normal</item>
<item name="fontPath">fonts/Roboto-Italic.ttf</item>
</style>
<style name="TextAppearance.FontPath" parent="android:TextAppearance">
<!-- Custom Attr-->
<item name="fontPath">fonts/Roboto-Italic.ttf</item>
</style>
<style name="MyActionBar.MenuTextStyle" parent="style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">@color/white</item>
</style>
<style name="Theme.SelectDate" parent="@android:style/Theme.Holo.NoActionBar">
<item name="android:editTextStyle">@style/Widget.EditText.Black</item>
</style>
<style name="Widget.EditText.Black" parent="@android:style/Widget.EditText">
<item name="android:textColor">@color/appColor</item>
</style>
<!-- DIALOG STYLE -->
<style name="You.Dialog" parent="android:Theme.Holo.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowIsFloating">false</item>
</style>
<style name="DialogAnimation">
<item name="android:windowEnterAnimation">@anim/slide_in_top</item>
<item name="android:windowExitAnimation">@anim/slide_out_bottom</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
CustomEditText.java (support multiple typeface) https://gist.github.com/korrio/3e54a23d538ac587f1ca
I modified the CustomEditText with CalligraphyTypefaceSpan from (https://github.com/chrisjenx/Calligraphy)
Usage:
int selectionStart = et.getSelectionStart();
int selectionEnd = et.getSelectionEnd();
// et (CustomEditText)
et.setColor(Color.RED, selectionStart, selectionEnd);
et.setFont(TypefaceUtils.load(getActivity().getAssets(), "fonts/ThaiSansNeue-Black.ttf"),selectionStart,selectionEnd);
@zachtom nothing seems untowards, you would have to create a mini sample project as if you have done everything correctly it should just work, as does the CalligraphySample
Oh and FYI, dont inherit from Theme.AppCompat.Light.NoActionBar
then inherit your Text Styles from android.Widget.TextView
thats just wrong. Always use the AppCompat
styles where applicable.
@chrisjenx does Calligraphy ignore android:textViewStyle
if it is not initialized in the Application class? It keeps ignoring this attribute in my project too.
So it seems like a bug in the support library, which they say it is fixed but seems to me is not https://code.google.com/p/android/issues/detail?id=169873