0

How do I create a custom progressbar in Android that has a drawable for the progress and background items? this is a my source

<style parent="@android:style/Widget.ProgressBar" name="customProgressBar">
    <item name="android:indeterminateDrawable">@drawable/ic_refresh_white</item>
</style>



 <ProgressBar
            android:id="@+id/pdWithImage"
            android:layout_width="50dp"
            android:layout_height="50dp"
            style="@style/customProgressBar"
            android:layout_centerInParent="true" />

i added png image background but when i run my app progresbar not rotating how i can solve my problem?

BekaKK
  • 2,173
  • 6
  • 42
  • 80

1 Answers1

0
class ProgressDialog extends Dialog {

        private ImageView iv;

        public ProgressDialog(Context context, int resourceIdOfImage) {
            super(context, R.style.YourStyle);
            WindowManager.LayoutParams wlmp = getWindow().getAttributes();
            wlmp.gravity = Gravity.CENTER_HORIZONTAL;
            getWindow().setAttributes(wlmp);
            setTitle(null);
            setCancelable(false);
            setOnCancelListener(null);
            LinearLayout layout = new LinearLayout(context);
            layout.setOrientation(LinearLayout.VERTICAL);
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
            iv = new ImageView(context);
            iv.setImageResource(resourceIdOfImage);
            layout.addView(iv, params);
            addContentView(layout, params);
        }

        @Override
        public void show() {
            super.show();
            RotateAnimation anim = new RotateAnimation(0.0f, 360.0f, Animation.RELATIVE_TO_SELF, .5f, Animation.RELATIVE_TO_SELF, .5f);
            anim.setInterpolator(new LinearInterpolator());
            anim.setRepeatCount(Animation.INFINITE);
            anim.setDuration(3000);
            iv.setAnimation(anim);
            iv.startAnimation(anim);
        }
    }

And call this ProgressDialog method with image like this

ProgressDialog(activity, R.drawable.image)

hope it helps you :)

Ashwini Bhat
  • 500
  • 1
  • 4
  • 17