My applications UI is built using the Android Support Library, but there is currently no AppCompat version of the (intederminate) progressbar, which my app really needs.
This is an answer to an old question, but I figured fellow readers might be interested in this solution:
Newer versions (26.1.+) of the Support Library contain a class called CircularProgressDrawable that implements the exact look of the native Material indeterminate drawable. In order to easily use this in a layout, you can build a MaterialProgressBar
like this:
public class MaterialProgressBar extends ProgressBar{
// Same dimensions as medium-sized native Material progress bar
private static final int RADIUS_DP = 16;
private static final int WIDTH_DP = 4;
public MaterialProgressView(Context context, AttributeSet attrs) {
super(context, attrs);
// The version range is more or less arbitrary - you might want to modify it
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP
|| Build.VERSION.SDK_INT > Build.VERSION_CODES.O_MR1) {
final DisplayMetrics metrics = getResources().getDisplayMetrics();
final float screenDensity = metrics.density;
CircularProgressDrawable drawable = new CircularProgressDrawable(context);
drawable.setColorSchemeColors(getResources().getColor(R.color.colorPrimary));
drawable.setCenterRadius(RADIUS_DP * screenDensity);
drawable.setStrokeWidth(WIDTH_DP * screenDensity);
setIndeterminateDrawable(drawable);
}
}
}