Open MHKalantarian opened 5 years ago
I'd be also interested in this.
We did something similar in our app using custom text appearance styles. Not exactly what you want, but works well enough.
We did something similar in our app using custom text appearance styles. Not exactly what you want, but works well enough.
@masterjefferson May I have the custom view/class?
@MHKalantarian How did you solved this issue?
@basmaessen Custom class for every single view and not binding calligraphy on some pages!
@MHKalantarian And what if you have multiple fonts for 1 view
@basmaessen If you mean multiple fonts for 1 type of view you'll have to use a custom attribute or get the font in constructor but if you mean multiple fonts for 1 textfield
Multiple Typeface's per TextView / Spannables It is possible to use multiple Typefaces inside a TextView, this isn't new concept to Android.
This could be achieved using something like the following code.
SpannableStringBuilder sBuilder = new SpannableStringBuilder(); sBuilder.append("Hello!") // Bold this .append("I use Calligraphy"); // Default TextView font. // Create the Typeface you want to apply to certain text CalligraphyTypefaceSpan typefaceSpan = new CalligraphyTypefaceSpan(TypefaceUtils.load(getAssets(), "fonts/Roboto-Bold.ttf")); // Apply typeface to the Spannable 0 - 6 "Hello!" This can of course by dynamic. sBuilder.setSpan(typefaceSpan, 0, 6, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); setText(sBuilder, TextView.BufferType.SPANNABLE);
@MHKalantarian Do you have an example of a custom view for a TextView or Button or something?
@basmaessen a simple example for a textview
public class TextViewWithFont extends TextView {
public TextViewWithFont(Context context, AttributeSet attrs) {
super(context, attrs);
this.setTypeface(exampleTypeFace);
}
public TextViewWithFont(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
this.setTypeface(exampleTypeFace);
}
public TextViewWithFont(Context context) {
super(context);
this.setTypeface(exampleTypeFace);
}
}
I want to use separate fonts for BOLD & Italic textStyle. Is there any way to do this with the library? or any kind of workaround? I've tried writing custom classes for some views but Calligraphy overrides them :(