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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:35:11+00:00 2026-06-05T21:35:11+00:00

I have a progressBar using the ProgressBar class. Just doing this: progressBar = new

  • 0

I have a progressBar using the ProgressBar class.

Just doing this:

progressBar = new ProgressBar(this, null, android.R.attr.progressBarStyleHorizontal);

I need to change the color of that one, using input value like so:

int color = "red in RGB value".progressBar.setColor(color)

or something like that…

I can’t use an XML layout because the progress bar is customizable for users.

  • 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-06-05T21:35:13+00:00Added an answer on June 5, 2026 at 9:35 pm

    As I found help on a topic here but can’t remember the link, I’m posting my full solution which works great for my needs:

        // Draw a simple progressBar from xml
        progressBar = new ProgressBar(this, null, android.R.attr.progressBarStyleHorizontal);
    
        // Convert the color (Decimal value) to HEX value: (e.g: #4b96a0)
        String color = colorDecToHex(75, 150, 160);
    
        // Define a shape with rounded corners
        final float[] roundedCorners = new float[] { 5, 5, 5, 5, 5, 5, 5, 5 };
        ShapeDrawable pgDrawable = new ShapeDrawable(new RoundRectShape(roundedCorners,     null, null));
    
        // Sets the progressBar color
        pgDrawable.getPaint().setColor(Color.parseColor(color));
    
        // Adds the drawable to your progressBar
        ClipDrawable progress = new ClipDrawable(pgDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL);
        progressBar.setProgressDrawable(progress);
    
        // Sets a background to have the 3D effect
        progressBar.setBackgroundDrawable(Utils.getActivity().getResources()
                .getDrawable(android.R.drawable.progress_horizontal));
    
        // Adds your progressBar to your layout
        contentLayout.addView(progressBar);
    

    And here is the code to convert DECIMAL color values to HEXADECIMAL:

    public static String colorDecToHex(int p_red, int p_green, int p_blue)
    {
        String red = Integer.toHexString(p_red);
        String green = Integer.toHexString(p_green);
        String blue = Integer.toHexString(p_blue);
    
        if (red.length() == 1)
        {
            red = "0" + red;
        }
        if (green.length() == 1)
        {
            green = "0" + green;
        }
        if (blue.length() == 1)
        {
            blue = "0" + blue;
        }
    
        String colorHex = "#" + red + green + blue;
        return colorHex;
    }
    

    I think the last method is not that clean but it works well.

    Hope this well help, too much time wasted on this progressbar.

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

Sidebar

Related Questions

I have added a label to the jquery ui progressbar using this demo .
For a few days a have some problem. I need to show simple ProgressBar
I have a ProgressBar. It works ok but I need to show the max
I have this Jquery AJAX request to process the creation of Word documents (using
I have am using a This LoaderImageView in a gallery. 1st I show a
I just started doing Java Swing applications using MVC pattern and so far i
I have a WPF project using CM. I have a progress bar that I
I have an image called 'progressbar.png'. Is there a way that I could crop
I have been playing around with the Silverlight progressbar a while and no matter
I have created a form on which two components are present, button and progressbar

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.