当前位置:   article > 正文

Android progressBar代码设置进度条颜色、背景颜色以及圆角显示_android progressbar设置背景两边及进度显示圆角

android progressbar设置背景两边及进度显示圆角

效果如下:

Java代码设置如下:

  1. int roundRadius = 15; // 8dp 圆角半径 The x-radius of the oval used to round the corners
  2. //准备progressBar带圆角的背景Drawable
  3. GradientDrawable progressBg = new GradientDrawable();
  4. //设置圆角弧度
  5. progressBg.setCornerRadius(roundRadius);
  6. //设置绘制颜色
  7. progressBg.setColor(getResources().getColor(R.color.color_efefef));
  8. //准备progressBar带圆角的进度条Drawable
  9. GradientDrawable progressContent = new GradientDrawable();
  10. progressContent.setCornerRadius(roundRadius);
  11. //设置绘制颜色,此处可以自己获取不同的颜色
  12. progressContent.setColor(getColorForIndex(position));
  13. //ClipDrawable是对一个Drawable进行剪切操作,可以控制这个drawable的剪切区域,以及相相对于容器的对齐方式
  14. ClipDrawable progressClip = new ClipDrawable(progressContent, Gravity.LEFT, ClipDrawable.HORIZONTAL);
  15. //Setup LayerDrawable and assign to progressBar
  16. //待设置的Drawable数组
  17. Drawable[] progressDrawables = {progressBg, progressClip};
  18. LayerDrawable progressLayerDrawable = new LayerDrawable(progressDrawables);
  19. //根据ID设置progressBar对应内容的Drawable
  20. progressLayerDrawable.setId(0, android.R.id.background);
  21. progressLayerDrawable.setId(1, android.R.id.progress);
  22. //设置progressBarDrawable
  23. progressBar.setProgressDrawable(progressLayerDrawable);
  24. //设置进度值
  25. progressBar.setProgress(item.getValue());

参考博客:

https://www.jianshu.com/p/c146419fc1b2

https://blog.csdn.net/buptlzx/article/details/8294979

https://blog.51cto.com/glblong/1739160

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/474161
推荐阅读
相关标签
  

闽ICP备14008679号