第一次写博客,有纰漏请见谅。Sweety
1、找到XML中的progressBar
ProgressBar progressBar = (ProgressBar)findViewById(。。。);
2、设置背景层和进度层
Drawable[ ] layers = new Drawable[2];
背景层:
int[ ] color = {Color.White, Color.White};
GradientDrawable background = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, colors);
background.setCornerRadius(12);
进度层:
int [ ] proColors = {Color.Red, Color.Blue};
GradientDrawable progressBar = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, proColors);
progressBar.setCornerRadius(12);
ClipDrawable clipDrawable = new ClipDrawable(progressDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL);
合成:
layers[0] = background;
layers[1] = clipDrawable ;
LayerDrawable layer = new LayerDrawable(layers);
layer.setId(0, android.R.id.background);
layer.setId(1, android.R.id.progress);
最后一步
progressBar.setProgressDrawable(layer);