florent37 / MaterialViewPager

A Material Design ViewPager easy to use library
https://www.fiches-plateau-moto.fr
Apache License 2.0
8.13k stars 1.48k forks source link

Having problems changing header image to a local drawable file rather than pull from URL. #212

Open TheGreenBastard opened 8 years ago

TheGreenBastard commented 8 years ago

Hello All, Im new here and have been banging my head against the wall for 2 days trying to get this to work. I am trying to change a string value to a drawable value.

The readme doc says i can use fromColorResAndDrawable in place of fromColorResAndUrl

example code that works and pulls the image...

return HeaderDesign.fromColorResAndUrl( R.color.green, "http://www.tothemobile.com/wp-content/uploads/2014/07/original.jpg");

I changed the code to....

return HeaderDesign.fromColorResAndDrawable( R.color.green, "@drawable/my_header");

I receive an error...

required: int,Drawable found: int,String

so I guess what i need to know is how do i return a Drawable rather than a string?

I must have tried it 20 different ways and im at a loss for what to try next. Any help would be greatly appreciated. Thank You.

bloderxd commented 8 years ago

Try get your image from drawable by this resource string

"android.resource://your_package_name/drawable/your_image_name"

TheGreenBastard commented 8 years ago

nope still not working tried it with and without the .png on the end

bloderxd commented 8 years ago

but did you tried in HeaderDesign.fromColorResAndDrawable function or HeaderDesign.fromColorResAndUrl?

TheGreenBastard commented 8 years ago

been using fromColorResAndDrawable, since it errors every time, i even do a test once it fails the first time. I change 2/4 references back to fromColorResAndUrl and 2/4 of the header calls to fromColorResAndDrawable. it still gives me 4 errors every time.

bloderxd commented 8 years ago

Could you paste here the errors, please?

Murgio commented 8 years ago

Try this code:

return HeaderDesign.fromColorResAndDrawable(
R.color.green,
getResources().getDrawable(R.drawable.my_header));
TheGreenBastard commented 8 years ago

that worked, thank you Murgio. I still get a depreciated error on the getDrawable, but at least it runs. I can work around the depreciation later.

TheGreenBastard commented 8 years ago

Upon further inspection that doesnt work. I end up showing the first image for case 1 but upon changing tabs the program errors in a 2-4 pages. The remaining drawables never show up while the app is running.

sheveron commented 8 years ago

Hi,

This is what I use...

Bitmap bm = BitmapFactory.decodeResource(getResources(), R.myJPGFile);
Drawable bmDrawable = new BitmapDrawable(getResources(), bm);
return HeaderDesign.fromColorResAndDrawable(R.color.red, bmDrawable);

Hope helps.

Shaun

TUSHARZ commented 7 years ago

return "HeaderDesign.fromColorResAndDrawable(R.color.red , ContextCompat.getDrawable(context,R.drawable.your_drawable))

This will work for sure