mytechead

Android & Wordpress Help center

Archive for the tag “getProgress”

Set resource of ‘setprogressDrawable’ programmatically

If your a re trying to create a custom progressbar for your android application, setProgressDrawable method might come handy in doing so.

The method setProgressDrawable expects a parameter of type Drawable which is basically your custom image/color/gradient that you want to set.

But there is a slight catch when  setProgressDrawable method is used, when you set the resource it will set correctly but when you’ll run your program you wont be able to

see it on the actual page. This is because the bounds are not set for the progress bar and you need to do this using the following code –

// get progress bar bounds.
Rect bounds = seekBar.getProgressDrawable().getBounds();

seekBar.setProgressDrawable(getResources().getDrawable(R.drawable.your_drawable));

seekBar.getProgressDrawable().setBounds(bounds);

This will correctly set the drawable image.

Post Navigation