Looking at the ProgressBar source code, it looks like setIndeterminateDrawable
doesn't call updateDrawableBounds
so you'll have to manually set the bounds on your new drawable.
Android ProgressBar setIndeterminateDrawable()
-
05-07-2023 - |
Pregunta
I'm trying to change a progress bar's indeterminate drawable on an event. When calling
mProgressBar.setIndeterminateDrawable(drawable);
The progress has no background. The drawable is valid and works if I set it in XML. Any idea's on how to fix this issue?
Solución
Otros consejos
After setting new drawable, we have to set its bounds.
Drawable drawable = getResources().getDrawable(R.drawable.your_new_custom_drawable);
Rect bounds = progress.getIndeterminateDrawable().getBounds(); // re-use bounds from current drawable
progress.setIndeterminateDrawable(drawable); // set new drawable
progress.getIndeterminateDrawable().setBounds(bounds); // set bounds to new drawable
After setIndeterminateDrawable() you must call requestLayout()
Ex:
progressBar.setIndeterminateDrawable(yourDrawable)
progressBar.requestLayout();
The same question was answered here: progressBar.setIndeterminateDrawable() doesn't work
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow