I'm using an horizontal progress bar in my Android application, and I want to change its progress color (which is Yellow by default). How can I do it using code
(not XML)?
相关问题
- 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
There's probably one thing that hasn't been referred to in this answer:
If your theme is inheriting from
Theme.AppCompat
,ProgressBar
will assume the color you defined as"colorAccent"
in your theme.So, using..
..will tint the color of the ProgressBar automagically to the
@color/custom_color
.Hit the same problem while working on modifying the look/feel of the default progress bar. Here is some more info that will hopefully help people :)
a-z0-9_.
(ie. no capitals!)R.drawable.filename
myProgressBar.setProgressDrawable(...)
, however you need can't just refer to your custom layout asR.drawable.filename
, you need to retrieve it as aDrawable
:Apply this custom style to the progress bar.
@drawable/progress.xml -
Use this type of image for progress bar.
For better result you can use multiple progress images. And please don't hesitate using images, because Android Platform itself use images for progressbar. The code is extracted from sdk :)
All API
if use all API just create the theme in style
style.xml
and use in progress
API level 21 and higher
if used in API level 21 and higher just use this code:
As per muhammad-adil suggested for SDK ver 21 and above
in XML Works for me, is easy enough.