Android – How to load NavigationView menu item icon from URL using Picasso

    // this set prevents collecting targets by garbage collector
    final Set<Target> targets = new HashSet<>();

    private void loadMenuIcon(final MenuItem menuItem, String url) {

        Target target = new Target() {
            @Override
            public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom loadedFrom) {
                BitmapDrawable mBitmapDrawable = new BitmapDrawable(getResources(), bitmap);
                menuItem.setIcon(mBitmapDrawable);
            }

            @Override
            public void onBitmapFailed(Drawable drawable) {}

            @Override
            public void onPrepareLoad(Drawable drawable) {}
        };

        targets.add(target);

        Picasso.with(this).load(url).into(target);

    }

Usage:

            Menu menu = navigationView.getMenu();
            MenuItem item = menu.add(0, id, i, name);
            loadMenuIcon(item, url);