SRBhagwat
SRBhagwat

Reputation: 1521

loading an image from url for the navigation drawer header background

I am using mikepenz material drawer.This is my code where header of a navigation drawer is set with an image which is in drawable folder.This works fine.But how to load image from URL and set it as header background image (imageOne in this case)?

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();

Upvotes: 1

Views: 2455

Answers (1)

Evgeniy Mishustin
Evgeniy Mishustin

Reputation: 3804

You can skip the withHeaderBackground(R.drawable.imageOne) line in your code. Instead, use this two lines (I'm using Glide library for this example):

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

It works. If you have any other question I'll be glad to help. If you aren't familiar with Glide or Picasso library you can google it - there are plenty of tutorials. Hope it helped.

Upvotes: 2

Related Questions