【问题标题】:Progressbar not showing any color change进度条没有显示任何颜色变化
【发布时间】:2013-01-18 06:17:25
【问题描述】:

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

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

【问题讨论】:

    标签: android android-progressbar


    【解决方案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);
    

    【讨论】:

    • 感谢这个技巧,但我不想在我的代码中使用 Html 类
    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

      像这样试试..

        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

      【讨论】:

      • ,我试过了,但我的应用程序崩溃了。它在 logcat 中显示未知颜色
      • 在 MyColor 字符串中选择不同的颜色
      • 它不适用于developer.android.com/reference/android/…中给出的颜色代码
      • @Abhilash 你想以编程方式执行此操作
      • @Abhilash 检查以上链接进度条
      【解决方案4】:

      试试这样"

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

      first:设置可绘制边界 第二:设置progressdrawable 第三:设置进度

      【讨论】:

        猜你喜欢
        • 2020-12-23
        • 1970-01-01
        • 2018-09-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-12-23
        • 1970-01-01
        • 2012-01-23
        相关资源
        最近更新 更多