mikepenz material drawer can not load url for drawer item

馋奶兔 提交于 2019-12-25 06:38:42

问题


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

please help me. Thanks


回答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 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




回答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 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 @.@



来源:https://stackoverflow.com/questions/32686640/mikepenz-material-drawer-can-not-load-url-for-drawer-item

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!