0

I use mikepenz material drawer too, but I met issue about loading URL to update drawer item icon, but still failed. I can not solve it. https://github.com/mikepenz/MaterialDrawer

enter image description here

please help me. Thanks

NoNaMe
  • 6,020
  • 30
  • 82
  • 110
Luna Kong
  • 3,065
  • 25
  • 20

2 Answers2

8

As of the latest version of the MaterialDrawer it is now recommend to use the AbstractDrawerImageLoader and overwrite the specific methods.

Using glide:

//initialize and create the image loader logic
DrawerImageLoader.init(new AbstractDrawerImageLoader() {
        @Override
        public void set(ImageView imageView, Uri uri, Drawable placeholder) {
            Glide.with(imageView.getContext()).load(uri).placeholder(placeholder).into(imageView);
        }

        @Override
        public void cancel(ImageView imageView) {
            Glide.clear(imageView);
        }
});

Or picasso:

//initialize and create the image loader logic
DrawerImageLoader.init(new AbstractDrawerImageLoader() {
        @Override
        public void set(ImageView imageView, Uri uri, Drawable placeholder) {
            Picasso.with(imageView.getContext()).load(uri).placeholder(placeholder).into(imageView);
        }

        @Override
        public void cancel(ImageView imageView) {
            Picasso.with(imageView.getContext()).cancelRequest(imageView);
        }
});

You can find a full implementation including sample code on how to define different placeholders for different targets in the GitHub repository of the MaterialDrawer. Here's the implementation of the CustomApplication

mikepenz
  • 12,708
  • 14
  • 77
  • 117
1

Fixed this issue.

The MaterialDrawer supports fetching images from URLs and setting them for the Profile icons. As the MaterialDrawer does not contain an ImageLoading library the dev can choose his own implementation

Need to implement this method in your application class.

//initialize and create the image loader logic
DrawerImageLoader.init(new DrawerImageLoader.IDrawerImageLoader() {
  @Override
  public void set(ImageView imageView, Uri uri, Drawable placeholder) {
    Picasso.with(imageView.getContext()).load(uri).placeholder(placeholder).into(imageView);
  }

  @Override
  public void cancel(ImageView imageView) {
    Picasso.with(imageView.getContext()).cancelRequest(imageView);
  }

  @Override
  public Drawable placeholder(Context ctx) {
    return null;
  }
});

Have fun @.@

Luna Kong
  • 3,065
  • 25
  • 20