您的位置:首页 > 移动开发 > Android开发

Android笔记:根据进度代码改变progressbar背景颜色,ClipDrawable,LayerDrawable,setProgressDrawable

2016-01-27 13:07 666 查看
做个笔记,主要是需要使用ClipDrawable、LayerDrawable:
private void setProgressBg(int progress) {
int a = progress * 255 / 100;
int color = Color.argb(a, 255, 90, 147);
ColorDrawable colorDrawable = new ColorDrawable();
colorDrawable.setColor(color);
ClipDrawable clipDrawable = new ClipDrawable(colorDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL);

Drawable drawable = getResources().getDrawable(R.color.transparent);
Drawable[] layers = new Drawable[]{drawable,clipDrawable};
LayerDrawable layerDrawable = new LayerDrawable(layers);
layerDrawable.setDrawableByLayerId(0,drawable);
layerDrawable.setDrawableByLayerId(1,clipDrawable);
progressBar.setProgressDrawable(clipDrawable);

progressBar.setProgress(0);
progressBar.setProgress(progress);

Loger.d("Vote投票", "result = " + progress);
Loger.d("Vote投票", "a = " + a);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  代码 进度 Android