使用Glide在MenuItem中加载远程图像 [英] Load a remote image in a MenuItem using Glide

查看:93
本文介绍了使用Glide在MenuItem中加载远程图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常,如果要使用Glide加载图像,我会写以下内容:

Usually if I want to load an image with Glide I would write the following:

Glide.with(context)
     .load(theURLOftheImage)
     .error(R.drawable.ic_error_image)
     .into(theImageView);

但是如果我需要将该URL的图像加载到必须实时更改的MenuItem中,该​​怎么办?

but what if I need to load the image of that URL into a MenuItem that has to be changed in real time?

以下是不可能的,因为方法into不接受参数:

The following is not possible because the method into does not accept the parameter:

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem settingsItem = menu.findItem(R.id.actionbar_menu_profile_actions);
    if (changeImage) {
        Glide.with(this).load(theURLOftheImage).error(R.drawable.ic_error_image).into(settingsItem);
    }
    return super.onPrepareOptionsMenu(menu);
}

推荐答案

使用针对 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆