private void init(AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        final Context context = getContext();
        final Resources resource = getResources();

        if (attrs == null) {
            // default we init a circle style loading drawable
            setProgressStyle(STYLE_CIRCLE);
            return;
        }

        final float density = resource.getDisplayMetrics().density;
        // default size 2dp
        final int baseSize = (int) (density * 2);

        // Load attributes
        final TypedArray a = context.obtainStyledAttributes(
                attrs, R.styleable.Loading, defStyleAttr, defStyleRes);

        int bgLineSize = a.getDimensionPixelOffset(R.styleable.Loading_gBackgroundLineSize, baseSize);
        int fgLineSize = a.getDimensionPixelOffset(R.styleable.Loading_gForegroundLineSize, baseSize);

        int bgColor = 0;// transparent color
        ColorStateList colorStateList = a.getColorStateList(R.styleable.Loading_gBackgroundColor);
        if (colorStateList != null)
            bgColor = colorStateList.getDefaultColor();

        int fgColor = Color.BLACK;
        int[] fgColorArray = null;
        try {
            fgColor = a.getColor(R.styleable.Loading_gForegroundColor, 0);
        } catch (Exception ignored) {
            int fgColorId = a.getResourceId(R.styleable.Loading_gForegroundColor, R.array.g_default_loading_fg);
            // Check for IDE preview render
            if (!isInEditMode()) {
                TypedArray taColor = resource.obtainTypedArray(fgColorId);
                int length = taColor.length();
                if (length > 0) {
                    fgColorArray = new int[length];
                    for (int i = 0; i < length; i++) {
                        fgColorArray[i] = taColor.getColor(i, Color.BLACK);
                    }
                } else {
                    String type = resource.getResourceTypeName(fgColorId);
                    try {
                        switch (type) {
                            case "color":
                                fgColor = resource.getColor(fgColorId);
                                break;
                            case "array":
                                fgColorArray = resource.getIntArray(fgColorId);
                                break;
                            default:
                                fgColorArray = resource.getIntArray(R.array.g_default_loading_fg);
                                break;
                        }
                    } catch (Exception e) {
                        fgColorArray = resource.getIntArray(R.array.g_default_loading_fg);
                    }
                }
                taColor.recycle();
            }
        }

        int style = a.getInt(R.styleable.Loading_gProgressStyle, 1);
        boolean autoRun = a.getBoolean(R.styleable.Loading_gAutoRun, true);

        float progress = a.getFloat(R.styleable.Loading_gProgressFloat, 0);

        a.recycle();

        setProgressStyle(style);
        setAutoRun(autoRun);
        setProgress(progress);

        setBackgroundLineSize(bgLineSize);
        setForegroundLineSize(fgLineSize);
        setBackgroundColor(bgColor);

        if (fgColorArray == null) {
            setForegroundColor(fgColor);
        } else {
            setForegroundColor(fgColorArray);
        }
    }
This is android loading view,
You can use it to show progress bar.
<p>
<p><strong>XML attributes</strong></p>
<p>
See {@link net.qiujuer.genius.ui.R.styleable#Loading_gAutoRun Attributes},
{@link net.qiujuer.genius.ui.R.styleable#Loading_gBackgroundColor Attributes},
{@link net.qiujuer.genius.ui.R.styleable#Loading_gBackgroundLineSize Attributes}
{@link net.qiujuer.genius.ui.R.styleable#Loading_gForegroundColor Attributes}
{@link net.qiujuer.genius.ui.R.styleable#Loading_gForegroundLineSize Attributes}
{@link net.qiujuer.genius.ui.R.styleable#Loading_gProgressFloat Attributes}
{@link net.qiujuer.genius.ui.R.styleable#Loading_gProgressStyle Attributes}
caprice/ui/src/main/java/net/qiujuer/genius/ui/widget/Loading.java