从url加载图像以获取导航抽屉标题背景

时间:2015-08-12 05:48:01

标签: android navigation-drawer

我正在使用mikepenz材质抽屉。这是我的代码,其中导航抽屉的标题设置有可绘制文件夹中的图像。这很好。但是如何从URL加载图像并将其设置为标题背景图像( 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();

1 个答案:

答案 0 :(得分:2)

您可以跳过代码中的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库,您可以谷歌搜索 - 有很多教程。希望它有所帮助。