0

I have successfully changed the color of my progress bar to the colors available in Color (blue, green etc.), but when I give the hexcode of a particular color I get a bar with nothing in it. How can I resolve this?

ProgressBar pg = (ProgressBar)findViewById(R.id.progressBarDownload);
final float[] roundedCorners = new float[] { 5, 5, 5, 5, 5, 5, 5, 5 };
ShapeDrawable progressDrawable = new ShapeDrawable(new RoundRectShape(roundedCorners, null,null));
progressDrawable.getPaint().setColor(0x01060012);//<-----problem here?
ClipDrawable progress = new ClipDrawable(progressDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL);
pg.setProgressDrawable(progress);   
pg.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.progress_horizontal));
pg.setProgress(40);
Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
Abx
  • 2,852
  • 4
  • 30
  • 50

4 Answers4

1

Use this code its works for me

            String source = "<b><font color=#ff0000> Loading. Please wait..."
                    + "</font></b>";
            pd = ProgressDialog.show(Main.this, "",

            Html.fromHtml(source), true);
            pd.setProgressStyle(ProgressDialog.STYLE_SPINNER);
MuraliGanesan
  • 3,233
  • 2
  • 16
  • 22
1

Try to use RGB values instead of hex color code, you can easily find the RGB values of the hex color code using ColorPic or any other similar tool.

Umesh
  • 2,704
  • 19
  • 21
0

Try like this..

  ProgressBar pg = (ProgressBar)row.findViewById(R.id.progress);
    final float[] roundedCorners = new float[] { 5, 5, 5, 5, 5, 5, 5, 5 };
    pgDrawable = new ShapeDrawable(new RoundRectShape(roundedCorners, null,null));
    String MyColor = "#FF00FF";
    pgDrawable.getPaint().setColor(Color.parseColor(MyColor));
    ClipDrawable progress = new ClipDrawable(pgDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL);
    pg.setProgressDrawable(progress);   
    pg.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.progress_horizontal));
    pg.setProgress(45);

import this

import android.graphics.drawable.*;

progressbar

Community
  • 1
  • 1
Janmejoy
  • 2,721
  • 1
  • 20
  • 38
0

try like this"

Drawable progressDrawablePause = MainActivity.this.getResources().getDrawable(R.drawable.download_progressbar_pause_bg);
            progressDrawablePause.setBounds(bar.getProgressDrawable().getBounds());
            bar.setProgressDrawable(progressDrawablePause);
            bar.setProgress(60);

first: set the drawable bounds second: set the progressdrawable third:setprogress

perry
  • 856
  • 1
  • 10
  • 22