I try to use Glide to load an external image and display it in a toolbar. I have the following code (inside a Fragment):
ImageView image = null;
Glide.with(this)
.load("https://images.unsplash.com/photo-1612138210955-363d1ba3477d?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=1080&fit=max")
.into(image);
binding.toolbar.setBackgroundResource(image);
The method 'binding.toolbar.setBackgroundResource()' requires an int but the loaded image from Glide is an imageView. Now my question is, how can I convert the loaded image from Glide into an int sucht that I can use the method 'binding.toolbar.setBackgroundResource(image)'? I'd appreciate every comment.
Update: I tried the suggested code from one answer which looks like this:
ImageView image = new ImageView(getContext());
image.setDrawingCacheEnabled(true);
Glide.with(this).load("https://images.unsplash.com/photo-1614907301762-405163ba662f?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80")
.into(image);
Bitmap bmap = image.getDrawingCache();
binding.toolbar.setBackground(new BitmapDrawable(getResources(), bmap));
Basically I do not get an error now. HOWEVER, the code should set the background of a toolbar. Basically the toolbar looks quite bad when using the suggested code because I can't see the picture but just a white area.I think the problem is the URL. I tried it with a non-existing URL and I get the same result. Just a white area. So this means that Glide can't load the image altough the URL itself is correct. Can you think about a specific reason why this problem occurs? –
As I have still not received an answer containing a solution to my problem, I would like to ask you again whether you know how to solve the problem? How can I just load an Image via Glide from a URL and insert it as the background of a toolbar?