mytechead

Android & Wordpress Help center

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.

Advertisements

Single Post Navigation

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: