在Android中,ProgressDrawable 是一个用于显示进度条的 Drawable
ProgressBar 实例:ProgressBar progressBar = new ProgressBar(context, null, android.R.attr.progressBarStyleHorizontal);创建一个 ShapeDrawable 作为背景:ShapeDrawable backgroundDrawable = new ShapeDrawable();backgroundDrawable.getPaint().setColor(Color.GRAY);创建一个 ClipDrawable 作为进度条:ClipDrawable progressDrawable = new ClipDrawable(backgroundDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL);将 ClipDrawable 设置为 ProgressBar 的进度 Drawable:progressBar.setProgressDrawable(progressDrawable);设置进度条的最大值和当前进度:progressBar.setMax(100); // 设置最大值为100progressBar.setProgress(50); // 设置当前进度为50将 ProgressBar 添加到布局中:ViewGroup layout = findViewById(R.id.your_layout);layout.addView(progressBar);更新进度条的进度:int newProgress = 75;progressBar.setProgress(newProgress);这样,你就可以在代码中控制 ProgressDrawable 的进度了。注意,你需要根据实际情况调整上述代码中的参数和颜色。


