进度条未显示任何颜色变化

时间:2013-01-18 06:17:25

标签: android android-progressbar

我已成功将进度条的颜色更改为颜色(蓝色,绿色等)中可用的颜色,但是当我给出特定颜色的十六进制代码时,我会得到一个没有任何内容的条形图。我该如何解决这个问题?

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);

4 个答案:

答案 0 :(得分:1)

使用此代码对我有用

            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);

答案 1 :(得分:1)

尝试使用RGB值而不是十六进制颜色代码,您可以使用ColorPic或任何其他类似工具轻松找到十六进制颜色代码的RGB值。

答案 2 :(得分:0)

试试这样..

  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);

导入此

导入android.graphics.drawable。*;

progressbar

答案 3 :(得分:0)

试试这个“

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

首先:设置可绘制边界 第二:设置progressdrawable 第三名:setprogress