I want to create a bar like this initially when progress is zero it will be a fade in color but and as progress goes on it will become bright on that part(This is best I can explain) main thing is i want bar to show all colors at the same time.
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
You can't actually set the progress bars to different colors. You can however use only the
on
drawable and get the effect that you want. You could just apply a layer mask. What I mean is add a Relative layout which is initially saydark grey
throughout i.e the gradient has only ONE color which is dark gray. Now, use code to set the gradient color on the left programmatically. Obviously the color on the left is going to be transparent. Learn more about Linear Gradients. That's about it. You just need to calculate the position from where the right gradient starts, rather where the left gradient(transparent
)ends.This method is slightly flawed and may not work on ALL devices.
The flawless method would be to create multiple
.9png
images and set the drawable of the progress dialog programmatically every time.Finally! I went on a mission to figure this out for you, so if this suffices, feel free to give me that bounty, haha.
Try using this in your layout:
which references this drawable (progressmask.xml):
and this image (colorprogress.png)
What it does is set the image as the background of a linearlayout, which contains a progressbar. The progressbar adds a semi-transparent black mask to the image to make it appear that the lights are off.
NOTE: In order to get this affect, I had to monkey with the progress bar (i.e. flip it, and set it to only 10 intervals. You will have to do some math to get the progress to line up with the image. i.e. setprogress((100-trueprogress)/10). Sorry I did not do this part for you.
This is what it will look like at progress 50% (the small x's and triangles will disappear on the device)
I hope this answers your question!
Like already suggested i think you should go for an layer-list and set multiple drawables then. Main problem on this is that i need to be resizeable. An fixed size solution would be quite easy to implement.
Clip your "on" drawable:
over your "off" drawable:
by using
res/drawable/custom_progress_drawable.xml
From an
Activity
, useor in xml, use
And here's the result when using
android:max="10"
in xml:It's a little bit off, but you could use
setMax()
with something more like10000
and do some offsetting calculations when callingsetProgress()
to make it cleaner.