Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any way to have multiple fonts for multiple textStyles? #15

Open
MHKalantarian opened this issue Feb 5, 2019 · 9 comments
Open

Any way to have multiple fonts for multiple textStyles? #15

MHKalantarian opened this issue Feb 5, 2019 · 9 comments

Comments

@MHKalantarian
Copy link

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 :(

@npag
Copy link

npag commented Feb 21, 2019

I'd be also interested in this.

@jeffypooo
Copy link

We did something similar in our app using custom text appearance styles. Not exactly what you want, but works well enough.

@MHKalantarian
Copy link
Author

MHKalantarian commented Feb 28, 2019

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?

@basmaessen
Copy link

@MHKalantarian How did you solved this issue?

@MHKalantarian
Copy link
Author

@basmaessen Custom class for every single view and not binding calligraphy on some pages!

@basmaessen
Copy link

@MHKalantarian And what if you have multiple fonts for 1 view

@MHKalantarian
Copy link
Author

MHKalantarian commented Jul 5, 2019

@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);

@basmaessen
Copy link

@MHKalantarian Do you have an example of a custom view for a TextView or Button or something?

@MHKalantarian
Copy link
Author

@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);
    }

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants