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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:35:41+00:00 2026-05-27T14:35:41+00:00

I know Spannable can help me color any specific letters in a textview. However,

  • 0

I know Spannable can help me color any specific letters in a textview. However, is it possible to color 1/2 or 1/3 of a letter. I wanted to color text within a textview by percentage instead of by letter. Thanks for reading, and please let me know if you had some idea or solution to this.

thanks

  • 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-27T14:35:42+00:00Added an answer on May 27, 2026 at 2:35 pm

    It may be easier to use Spanned thought android.text.HTML

    So something like this:

    Spanned text = HTML.fromHtml("Sp<span style=\"color:red\">ann</span>able");
    textView.setText(text);
    

    It can also be used to add images, but it a bit more complicated.


    UPDATE

    I re-read your question and thought of a solution. You could create a custom view that has two textViews in a FrameLayout (on top of each other) and then resize the one on the top relative to the percentage. Something like this:

    import android.content.Context;
    import android.content.res.ColorStateList;
    import android.util.AttributeSet;
    import android.widget.FrameLayout;
    import android.widget.TextView;
    
    public class ProgressTextView extends FrameLayout {
    
        private TextView backgroundTextView;
        private TextView foregroundTextView;
        private CharSequence text;
    
        private ProgressTextView(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
            init(context, attrs);
        }
    
        private ProgressTextView(Context context, AttributeSet attrs) {
            super(context, attrs);
            init(context, attrs);
        }
    
        private ProgressTextView(Context context) {
            super(context);
            init(context, null);
        }
    
        private void init(Context context, AttributeSet attrs) {
            backgroundTextView = new TextView(context);
            foregroundTextView = new TextView(context);
            addView(backgroundTextView);
            addView(foregroundTextView);
            // process custom attributeSet from xml to set the colours
        }
    
        public void setBackgroundTextColor(int color) {
            backgroundTextView.setTextColor(color);
        }
    
        public void setBackgroundTextColor(ColorStateList colors) {
            backgroundTextView.setTextColor(colors);
        }
    
        public void setForegroundTextColor(int color) {
            backgroundTextView.setTextColor(color);
        }
    
        public void setForegroundTextColor(ColorStateList colors) {
            backgroundTextView.setTextColor(colors);
        }
    
        public void setPercentage(float per) {
            foregroundTextView.setWidth((((float) backgroundTextView.getWidth()) / 100f) * per);
        }
    
        public void setText(CharSequence text) {
            this.text = text;
            backgroundTextView.setText(text);
            foregroundTextView.setText(text);
        }
    
        public CharSequence getText() {
            return text;
        }
    
    }
    

    PS: not tested 😉 just an idea


    MORE UPDATE

    Apparently, with this method the text gets shortened instead of just cropped as I expected. The maybe on creation of the foregroundTextView you could do this:

    foregroundTextView = new TextView(context) {
    
        @Override
        protected void onDraw (Canvas canvas) {
            super.onDraw(canvas);
            Rect bounds = canvas.getClipBounds();
            bounds.right (((float) bounds.right) / 100.0f) * per;
            canvas.clipRect(bounds);
        }
    };
    

    And also add the per variable and modify setPercentage(float per) to be just a setter:

    private float per = 0.0f;
    
    public void setPercentage(float per) {
        this.per = per;
    }
    

    Hope this one works 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is this possible to set different textSize in one TextView? I know that I
Know of any good libraries for this? I did some searches and didn't come
Know if it's possible to access the iPhone compass in Safari using JavaScript? I
Anyone know if it's possible to databind the ScaleX and ScaleY of a render
I know that I can do something like $int = (int)99; //(int) has a
I know very little about Agile but I wonder if there is any difference
I know regex and substrings is a common question on here but i can
I KNOW I did this in WP7 (not WP7.1) and I can't figure out
Know of any tutorials or resources to configure Openfire Server to use it's built
I know jquery have backwardscompatibility files. But if you link to this specific version:

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.