2013-06-28 48 views
0

下面是我的代碼只是一個簡單的進度條。進度條 - 沒有信息只是加載欄

我的問題是:

  • 如何刪除該彈出進度條上顯示的文本/信息,所以ONY的yelow吧?
  • 另外,我可以將顏色從黃色更改爲藍色嗎?

    public class MainActivity extends Activity { 
    
    Button btnStartProgress; 
    ProgressDialog progressBar; 
    private int progressBarStatus = 0; 
    private Handler progressBarHandler = new Handler(); 
    
    private long fileSize = 0; 
    
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.main_activity); 
    
        addListenerOnButton(); 
    
    } 
    
    public void addListenerOnButton() { 
    
        btnStartProgress = (Button) findViewById(R.id.button1); 
        btnStartProgress.setOnClickListener(
          new OnClickListener() { 
    
         @Override 
         public void onClick(View v) { 
    
         // progress bar dialog 
         progressBar = new ProgressDialog(v.getContext()); 
         progressBar.setCancelable(true); 
         progressBar.setMessage("Progress Bar ... "); 
         progressBar.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); 
         progressBar.setProgress(0); 
         progressBar.setMax(100); 
         progressBar.show(); 
    
         //reset progress bar status 
         progressBarStatus = 0; 
    
         //reset filesize 
         fileSize = 0; 
    
         new Thread(new Runnable() { 
          public void run() { 
          while (progressBarStatus < 100) { 
    
           // process some tasks 
           progressBarStatus = Tasks(); 
    
    
           try { 
           Thread.sleep(1000); 
           } catch (InterruptedException e) { 
           e.printStackTrace(); 
           } 
    
           // Update the progress bar 
           progressBarHandler.post(new Runnable() { 
           public void run() { 
            progressBar.setProgress(progressBarStatus); 
           } 
           }); 
          } 
    
          // progress 100% 
          if (progressBarStatus >= 100) { 
    
           // sleep 2 seconds, so that you can see the 100% 
           try { 
            Thread.sleep(2000); 
           } catch (InterruptedException e) { 
            e.printStackTrace(); 
           } 
    
           // close the progress bar dialog 
           progressBar.dismiss(); 
          } 
          } 
          }).start(); 
    
          } 
    
          }); 
    
        } 
    
    public int Tasks() { 
    
        while (fileSize <= 1000000) { 
    
         fileSize++; 
    
         if (fileSize == 100000) { 
          return 10; 
         } else if (fileSize == 200000) { 
          return 20; 
         } else if (fileSize == 300000) { 
          return 30; 
         } else if (fileSize == 500000) { 
          return 50; 
         } else if (fileSize == 900000) { 
          return 90; 
         } 
    
        } 
    
        return 100; 
    
    }} 
    

回答

0

我發現關於兩個漂亮的教程:

TUT1

TUT2

對於ProgresDialog的定製,檢查this。還有:

<style name="pbStyle" parent="android:Theme.Dialog"> 
<item name="android:textColor">#FFFFFFFF</item> 
<item name="android:background">#FF0000FF</item> 
<item name="android:windowBackground">@android:color/transparent</item> 
</style>