进度条 - 没有信息只是加载栏

时间:2013-06-28 11:42:43

标签: android text progressdialog android-progressbar

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

我的问题是:

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

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

1 个答案:

答案 0 :(得分: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>