Skip to content Skip to sidebar Skip to footer

Mikepenz Material Drawer Can Not Load Url For Drawer Item

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

Solution 1:

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 logicDrawerImageLoader.init(newAbstractDrawerImageLoader() {
        @Overridepublicvoidset(ImageView imageView, Uri uri, Drawable placeholder) {
            Glide.with(imageView.getContext()).load(uri).placeholder(placeholder).into(imageView);
        }

        @Overridepublicvoidcancel(ImageView imageView) {
            Glide.clear(imageView);
        }
});

Or picasso:

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

        @Override
        publicvoidcancel(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

Solution 2:

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 logicDrawerImageLoader.init(newDrawerImageLoader.IDrawerImageLoader() {
  @Overridepublicvoidset(ImageView imageView, Uri uri, Drawable placeholder) {
    Picasso.with(imageView.getContext()).load(uri).placeholder(placeholder).into(imageView);
  }

  @Overridepublicvoidcancel(ImageView imageView) {
    Picasso.with(imageView.getContext()).cancelRequest(imageView);
  }

  @OverridepublicDrawableplaceholder(Context ctx) {
    returnnull;
  }
});

Have fun @.@

Post a Comment for "Mikepenz Material Drawer Can Not Load Url For Drawer Item"