2013-01-18 29 views
0

我已成功地將我的進度條的顏色更改爲顏色(藍色,綠色等)中的顏色,但是當我給出特定顏色的十六進制代碼時,它。我該如何解決這個問題?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); 

回答

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

+0

類,我試過了,但我的應用程序崩潰。它顯示logcat中的未知顏色 – Abx

+0

在MyColor字符串中選擇diffent顏色 – Janmejoy

+0

@Abhila sh是否正在工作 – Janmejoy

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

感謝名單爲這個技巧,但我不想使用HTML在我的代碼 – Abx

1

嘗試,而不是使用十六進制顏色代碼的RGB值,你可以很容易地找到使用ColorPic或任何其他類似的十六進制顏色代碼的RGB值工具。

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