从 url 为导航抽屉 header 背景加载图像

loading an image from url for the navigation drawer header background

我正在使用 mikepenz material drawer.This 是我的代码,其中导航抽屉的 header 设置了可绘制的图像 folder.This works fine.But 如何从 URL 加载图像并将其设置为 header 背景图像(本例中为 imageOne)?

headerNavigationLeft = new AccountHeader()
            .withActivity(this)
            .withCompactStyle(false)
            .withHeaderBackground(R.drawable.imageOne)
            .withSavedInstance(savedInstanceState)
            .withOnAccountHeaderListener(new     AccountHeader.OnAccountHeaderListener() {
                @Override
                public boolean onProfileChanged(View view, IProfile     iProfile, boolean b) {

                    headerNavigationLeft.setBackgroundRes(R.drawable.imageTwo);
                    return true;
                }
            })
            .build();

您可以跳过代码中的 withHeaderBackground(R.drawable.imageOne) 行。相反,使用这两行(我在这个例子中使用 Glide 库):

ImageView cover = headerNavigationLeft.getHeaderBackgroundView(); //get your ImageView
Glide.with(context).load("URL_OF_YOUR_IMAGE").into(cover);//load the image into ImageView

有效。如果您有任何其他问题,我将很乐意提供帮助。如果您不熟悉 Glide 或 Picasso 库,您可以 google 它 - 有很多教程。希望它有所帮助。