Code Monkey home page Code Monkey logo

Comments (9)

npag avatar npag commented on August 19, 2024

I'd be also interested in this.

from calligraphy.

jeffypooo avatar jeffypooo commented on August 19, 2024

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

from calligraphy.

MHKalantarian avatar MHKalantarian commented on August 19, 2024

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?

from calligraphy.

basmaessen avatar basmaessen commented on August 19, 2024

@MHKalantarian How did you solved this issue?

from calligraphy.

MHKalantarian avatar MHKalantarian commented on August 19, 2024

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

from calligraphy.

basmaessen avatar basmaessen commented on August 19, 2024

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

from calligraphy.

MHKalantarian avatar MHKalantarian commented on August 19, 2024

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

from calligraphy.

basmaessen avatar basmaessen commented on August 19, 2024

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

from calligraphy.

MHKalantarian avatar MHKalantarian commented on August 19, 2024

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

}

from calligraphy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.