0

下面是我的代码,只是一个简单的进度条。

我的问题是:

  • 如何删除显示在该弹出进度条上的文本/信息,所以只有黄色条?
  • 另外,我可以将颜色从黄色更改为蓝色吗?

    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;
    
    }}
    
4

1 回答 1

0

我找到了两个很好的教程:

TUT1

TUT2

对于 ProgresDialog 的自定义,请选中。并且:

<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>
于 2013-06-28T12:03:55.790 回答