標籤:android 代碼 進度 背景 progressbar 顏色
做個筆記,主要是需要使用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);}
本文出自 “天空沒有痕迹但我飛過” 部落格,請務必保留此出處http://glblong.blog.51cto.com/3058613/1739160
Android筆記:根據進度代碼改變progressbar背景顏色,ClipDrawable,LayerDrawable,setProgressDrawable