试试这个代码:
ProgressBar pg = new ProgressBar(getApplicationContext());
pg.setMax(100);
对于夏洛克progressbar
,您可以使用此示例代码:在此代码中设置值mProgress
以设置最大值progressbar
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.Window;
public class Progress extends SherlockActivity {
Handler mHandler = new Handler();
Runnable mProgressRunner = new Runnable() {
@Override
public void run() {
mProgress += 2;
//Normalize our progress along the progress bar's scale
int progress = (Window.PROGRESS_END - Window.PROGRESS_START) / 100 * mProgress;
setSupportProgress(progress);
if (mProgress < 100) {
mHandler.postDelayed(mProgressRunner, 50);
}
}
};
private int mProgress = 100;
@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(SampleList.THEME); //Used for theme switching in samples
super.onCreate(savedInstanceState);
//This has to be called before setContentView and you must use the
//class in com.actionbarsherlock.view and NOT android.view
requestWindowFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.progress);
findViewById(R.id.go).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
if (mProgress == 100) {
mProgress = 0;
mProgressRunner.run();
}
}
});
}
}