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 4237676
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:48:17+00:00 2026-05-21T02:48:17+00:00

I already aware of this:- Typeface typefaceArial= Typeface.createFromAsset(context.getAssets(), arial.ttf); but when I create the

  • 0

I already aware of this:-
Typeface typefaceArial= Typeface.createFromAsset(context.getAssets(), “arial.ttf”);

but when I create the following class it works but it gives low memory warning issue.

public class MidColorTextView extends TextView
{

private CharSequence text;
private String token;
private static Context context;
private String colorSpan;
private int colorCode;
private static Typeface typefaceArial;

public MidColorTextView( Context context , AttributeSet attrs )
{
    super(context, attrs);
    this.context=null;
    this.context = context;


    for(int i = 0; i < attrs.getAttributeCount(); i ++ )
    {
        // Log.i(TAG, attrs.getAttributeName(i));
        /*
         * Read value of custom attributes
         */

        this.text = attrs.getAttributeValue("http://schemas.android.com/apk/res/com.lht", "text");

        this.token = attrs.getAttributeValue("http://schemas.android.com/apk/res/com.lht", "token");
        this.colorSpan = attrs.getAttributeValue("http://schemas.android.com/apk/res/com.lht", "colorSpan");
        // Log.i("TAG", "token " + token);
        // Log.i("TAG", "text " + text);
        // Log.i("TAG", "colorSpan " + colorSpan);

    }
    init();
}

private void init ()
{
    if(text.charAt(0) == '@')
    {
        String tempText = (String) text.subSequence(1, text.length());
        this.text = Html.fromHtml(getResources().getString(Integer.parseInt(tempText)));

    }
    if(token.charAt(0) == '@')
    {
        String tempText = (String) token.subSequence(1, token.length());
        this.token = getResources().getString(Integer.parseInt(tempText));
    }
    if(colorSpan.charAt(0) == '@')
    {
        String tempText = (String) colorSpan.subSequence(1, colorSpan.length());
        this.colorSpan = getResources().getString(Integer.parseInt(tempText));
    }

    setColorCode(Color.parseColor(colorSpan));

    CharSequence textWitoutToken = null;
    String tempString = text.toString();

    // ---------checking whether text containg token or not.
    if(tempString.contains(token))
    {
        textWitoutToken = setSpanBetweenTokens(text, token, new ForegroundColorSpan(colorCode));
    }
    else
    {
        textWitoutToken = text;
    }
    textContent = null;
    setText(textWitoutToken);
    setTypefaceArial ();
    setTypeface(getTypefaceArial ());

}



public int getColorCode ()
{
    return colorCode;
}

public void setColorCode ( int colorCode )
{
    this.colorCode = colorCode;
}

private CharSequence textContent;


public static Typeface getTypefaceArial ()
{
    return typefaceArial;
}
public static void setTypefaceArial ()
{
    MidColorTextView.typefaceArial= Typeface.createFromAsset(context.getAssets(), "arial.ttf");
}

}

  • 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-21T02:48:18+00:00Added an answer on May 21, 2026 at 2:48 am

    I solved this issue via using singleton class.
    I am giving the complete code so that it can help others.

    1. Define this in XML:

        xmlns:lht="http://schemas.android.com/apk/res/com.lht"     android:id="@+id/basicLayout"
    
        <com.xyz.util.MidColorTextView
                xyz:token="#" 
                xyz:colorSpan="@color/BrightRed"
                xyz:text="@string/AppraisingStaffBottomText_imanage"
                style="@style/contentDescriptionText" />
    

    2. Create class MidColorTextView

        package com.xyz.util;
    
        public class MidColorTextView extends TextView {
    
        private CharSequence text;
        private String token;
        private  Context context;
        private String colorSpan;
        private int colorCode;
    
    
        public MidColorTextView( Context context , AttributeSet attrs ) {
            super(context, attrs);
            this.context = context;
    
    
            for(int i = 0; i < attrs.getAttributeCount(); i ++ ) {
                // Log.i(TAG, attrs.getAttributeName(i));
                /*
                 * Read value of custom attributes
                 */
    
                this.text = attrs.getAttributeValue("http://schemas.android.com/apk/res/com.xyz", "text");
    
                this.token = attrs.getAttributeValue("http://schemas.android.com/apk/res/com.xyz", "token");
                this.colorSpan = attrs.getAttributeValue("http://schemas.android.com/apk/res/com.xyz", "colorSpan");
                // Log.i("TAG", "token " + token);
                // Log.i("TAG", "text " + text);
                // Log.i("TAG", "colorSpan " + colorSpan);
    
            }
            init();
        }
    
        private void init () {
    
            if(text.charAt(0) == '@') {
                String tempText = (String) text.subSequence(1, text.length());
                this.text = Html.fromHtml(getResources().getString(Integer.parseInt(tempText)));
    
            }
            if(token.charAt(0) == '@') {
                String tempText = (String) token.subSequence(1, token.length());
                this.token = getResources().getString(Integer.parseInt(tempText));
            }
            if(colorSpan.charAt(0) == '@')
            {
                String tempText = (String) colorSpan.subSequence(1, colorSpan.length());
                this.colorSpan = getResources().getString(Integer.parseInt(tempText));
            }
    
            setColorCode(Color.parseColor(colorSpan));
    
            CharSequence textWitoutToken = null;
            String tempString = text.toString();
    
            // ---------checking whether text containg token or not.
            if(tempString.contains(token))
            {
                textWitoutToken = setSpanBetweenTokens(text, token, new ForegroundColorSpan(colorCode));
            }
            else
            {
                textWitoutToken = text;
            }
            textContent = null;
            setText(textWitoutToken);
            setTypeface(FontManager.getInstance(context).getTypefaceArial ());
    
        }
    
        public void setText ( CharSequence text , String token , int color )
        {
            setText(setSpanBetweenTokens(text, token, new ForegroundColorSpan(color)));
    
            setTypeface(FontManager.getInstance(context).getTypefaceArial ());
    
        }
    
        public int getColorCode ()
        {
            return colorCode;
        }
    
        public void setColorCode ( int colorCode )
        {
            this.colorCode = colorCode;
        }
    
        private CharSequence textContent;
    
        public CharSequence setSpanBetweenTokens ( CharSequence text , String token , CharacterStyle... cs )
        {
            // Start and end refer to the points where the span will apply
            int tokenLen = token.length();
            int start = text.toString().indexOf(token) + tokenLen;
            int end = text.toString().indexOf(token, start);
            if(start > - 1 && end > - 1)
            {
                // Copy the spannable string to a mutable spannable string
                SpannableStringBuilder ssb = new SpannableStringBuilder(text);
                for(CharacterStyle c : cs)
                {
                    ssb.setSpan(c, start, end, 0);
                }
                // Delete the tokens before and after the span
                ssb.delete(end, end + tokenLen);
                ssb.delete(start - tokenLen, start);
    
                text = ssb;
                textContent = ssb;
                String tempString = textContent.toString();
                if(tempString.contains(token))
                {
                    setSpanBetweenTokens(textContent, token, new ForegroundColorSpan(colorCode));
                }
    
            }
    
            return textContent;
        }
    
        }
    

    3. Create class FontManager

    public class FontManager {
        private Typeface typefaceArial;
        private  Context context;
    
        private static FontManager instance = null;
    
        private FontManager(Context context) {
            this.context = context;
            this.typefaceArial= Typeface.createFromAsset(context.getAssets(), "arial.ttf");
        }
    
        public synchronized static FontManager getInstance(Context context) {
            if(instance == null) {
                instance = new FontManager(context);
            }
            return instance;
        }
    
        public Typeface getTypefaceArial () {
            return typefaceArial;
        }
    
    }
    

    This will solve all your problems.

    setSpanBetweenTokens is used for the color text between specific tokens.

    Here is a string resource to test on:

    <string name="AppraisingStaffBottomText_imanage">The meeting&lt;br>&lt;br>PAST&lt;br>Allow the employee to give you
            their view of their positive
            progress over the past period, focus them on this with open
            questions, such as:&lt;br>&lt;i>#\"What has been your important contribution over the past
            6
            months?\"#&lt;/i>&lt;br>&lt;i>#\"What have your learned about your role?\"#&lt;/i>&lt;br>
            &lt;i>#\"What has been your important success?\"#&lt;/i>&lt;br>Don\'t rake over past mistakes,
            don\'t focus on poor performance
            - you cannot change that, reserve those discussions future
            development - see below&lt;br>&lt;br>PRESENT&lt;br>Using open questions, help staff to identify
            their true strengths,
            capabilities, attributes, skills and attitudes. Create a
            comprehensive picture of them as a strategic contributor and
            resource.&lt;br>What are your skills, and to what level?&lt;br>&lt;i>#\"What have you added as
            capabilities over the past months?\"#&lt;/i>&lt;br>&lt;i>#\"What do you find are your
            most useful personal attributes in
            your role?\"#&lt;/i>&lt;br>&lt;br>FUTURE&lt;br>The future is the period where changes in
            capability and
            performance can be made.&lt;br>This discussion is where your people can figure out -
            with your
            help - what development they need to reach your performance
            standards and their career goals. It begins with understanding
            their career goals, so ....&lt;br>&lt;i>#\"What are your goals?\"#&lt;/i>&lt;br>&lt;i>#\"What
            development will be needed?\"#&lt;/i>
            &lt;br>&lt;i>#\"You have seen over the past months that you may need more skill in these
            areas .......................... what should we do about
            that?\"#&lt;/i>&lt;br>&lt;br>Finally: Agree a specific development plan that includes
            training/experience in the areas where more skill is needed. Fix dates
            in the diary&lt;br>&lt;br>The Manager\'s role is one of Mentor and Guide; not
            Judge and
            Jury</string>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am aware of this question already existing, but it has given me no
Yes, I'm aware that this question has already been post, but ... I'm looking
Im aware this may be a slightly odd question, but given a Page class
I am aware that this topic has been covered already in many places, but
Has anyone already tried this, anything particulair that I need to be aware of?
I'm already aware of some browser-specific DOM documentation out there (Gecko DOM Reference for
Already finished implementing the player. I want to implement the progress bar. But I
I already know how to: Load properties files into my Spring configuration using: <context:property-placeholder
I already know the obvious answer to this question: just download <insert favorite windows
I'm already aware that \w in PCRE (particularly PHP's implementation) can sometimes match some

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.