'How do I set an image view to an Icon?

I'm trying to load an image from Firebase Storage, put it inside an ImageView and set it to the bottom navigation bar icon, here's my code:

DocumentReference df = fstore.collection("Users").document(user.getUid());
    df.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
        @Override
        public void onComplete(@NonNull Task<DocumentSnapshot> task) {
            if (task.isSuccessful())
            {
                DocumentSnapshot doc = task.getResult();
                if (doc.exists())
                {
                    if (doc.get("profilePictureUrl")!= null) { //set profile pic into image view
                        String downloadUrl = doc.get("profilePictureUrl").toString();
                        Glide.with(BottomNavigationActivity.this).load(downloadUrl).into(profileImg);
                    }
                }
            }
        }
    });

    //set icon only accepts a drawable file
    bottomNav.getMenu().getItem(4).setIcon(profileImg);'

but the setIcon method can only receive a drawable file, how do I solve this problem?



Solution 1:[1]

If you need to set the image that you from downloadUrl to the icon that exists in the BottomNavigation, then you can convert it like this:

if (doc.get("profilePictureUrl")!= null) { //set profile pic into image view
    String downloadUrl = doc.get("profilePictureUrl").toString();
    Glide.with(BottomNavigationActivity.this)
        .load(downloadUrl)
        .into(profileImg);

    try {
        URL url = new URL(downloadUrl);
        InputStream inputStream = (InputStream) url.getContent();
        Drawable icon = Drawable.createFromStream(inputStream, "src name");
        bottomNav.getMenu().getItem(4).setIcon(icon);
    } catch (IOException e) {
        Log.e(TAG, e.getMessage());
    }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alex Mamo