MaterialViewPager icon indicating copy to clipboard operation
MaterialViewPager copied to clipboard

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

Open TheGreenBastard opened this issue 9 years ago • 10 comments

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.

TheGreenBastard avatar Jan 28 '16 14:01 TheGreenBastard

Try get your image from drawable by this resource string

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

bloderxd avatar Jan 29 '16 11:01 bloderxd

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

TheGreenBastard avatar Feb 01 '16 13:02 TheGreenBastard

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

bloderxd avatar Feb 01 '16 13:02 bloderxd

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.

TheGreenBastard avatar Feb 04 '16 00:02 TheGreenBastard

Could you paste here the errors, please?

bloderxd avatar Feb 04 '16 00:02 bloderxd

Try this code:

return HeaderDesign.fromColorResAndDrawable(
R.color.green,
getResources().getDrawable(R.drawable.my_header));

Murgio avatar Feb 04 '16 19:02 Murgio

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 avatar Feb 25 '16 16:02 TheGreenBastard

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.

TheGreenBastard avatar Feb 25 '16 16:02 TheGreenBastard

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

sheveron avatar Apr 03 '16 10:04 sheveron

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

This will work for sure

TUSHARZ avatar Jul 20 '17 12:07 TUSHARZ