Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7610211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:21:52+00:00 2026-05-31T01:21:52+00:00

I want to apply two different font styles to a text in a single

  • 0

I want to apply two different font styles to a text in a single TextView.

My case is same as Android – two sentences, two styles, one TextView. The only difference is that I want to set a Custom Font on the whole text. I have included Helvetica Font as an assets in my project and want to apply that font to the TextView with first part of the text will be Helvetica BOLD and remaining part Helvetica NORMAL. Any suggestions how it can be done ?

Text needed in following format. Custom text with different styles and single textview.

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T01:21:53+00:00Added an answer on May 31, 2026 at 1:21 am

    One way to do this is to extend TypefaceSpan:

    import android.graphics.Paint;
    import android.graphics.Typeface;
    import android.text.TextPaint;
    import android.text.style.TypefaceSpan;
    
        public class CustomTypefaceSpan extends TypefaceSpan {
            private final Typeface newType;
    
            public CustomTypefaceSpan(String family, Typeface type) {
                super(family);
                newType = type;
            }
    
            @Override
            public void updateDrawState(TextPaint ds) {
                applyCustomTypeFace(ds, newType);
            }
    
            @Override
            public void updateMeasureState(TextPaint paint) {
                applyCustomTypeFace(paint, newType);
            }
    
            private static void applyCustomTypeFace(Paint paint, Typeface tf) {
                int oldStyle;
                Typeface old = paint.getTypeface();
                if (old == null) {
                    oldStyle = 0;
                } else {
                    oldStyle = old.getStyle();
                }
    
                int fake = oldStyle & ~tf.getStyle();
                if ((fake & Typeface.BOLD) != 0) {
                    paint.setFakeBoldText(true);
                }
    
                if ((fake & Typeface.ITALIC) != 0) {
                    paint.setTextSkewX(-0.25f);
                }
    
                paint.setTypeface(tf);
            }
        }
    

    Then when you want to use two different typefaces call:

    String firstWord = "first ";
    String secondWord = "second";
    
    // Create a new spannable with the two strings
    Spannable spannable = new SpannableString(firstWord+secondWord);
    
    // Set the custom typeface to span over a section of the spannable object
    spannable.setSpan( new CustomTypefaceSpan("sans-serif",CUSTOM_TYPEFACE), 0, firstWord.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    spannable.setSpan( new CustomTypefaceSpan("sans-serif",SECOND_CUSTOM_TYPEFACE), firstWord.length(), firstWord.length() + secondWord.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    
    // Set the text of a textView with the spannable object
    textView.setText( spannable );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two elements, I want to apply same background style, but different font
I have two endpoints using annotations. I want to apply different interceptors to each
Summary: I want to save two classes of the same name and different namespaces
I have two MovieClips onscreen, and I want to apply the same mask to
I want to apply some CSS to text that I can't get marked up
If I want to use a domain class, e.g. MoneyTransaction, for two entirely different
Hi i have two tabs in my tab widget,i want to apply the two
CSS Question: If two different selectors apply to an element, who wins? I know
Possible Duplicate: How to apply the asp.net authorization in two different folders ? How
I want to display two different XSLT transformations in function of what the user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.