Library

compile('com.mikepenz:materialdrawer:4.4.6@aar') { transitive = true } 

Dynamically create NavigationDrawer and Header for it, I create it using

 AccountHeader accountHeader = new AccountHeaderBuilder() .withActivity(this) .withHeaderBackground(R.drawable.main_icon) .build(); 

and then add it to

 drawer = new DrawerBuilder(this) .withActivity(ActivityHome.this) .withAccountHeader(accountHeader) .withDisplayBelowStatusBar(true) .withToolbar(toolbar) .withActionBarDrawerToggleAnimated(true) .withSavedInstance(savedInstanceState) .addDrawerItems(primaryDrawerItems) .withSavedInstance(savedInstanceState) .withShowDrawerOnFirstLaunch(true) .build(); 

the image resource in the header added in this method .withHeaderBackground(R.drawable.main_icon) and in the end it looks like this

enter image description here

How to make the picture not stretch?

  • Well, probably in the source / dock rummage to this third-party solution in search of an answer. If you didn’t find it yourself, you could at least provide a link to the lib in use. - Yuriy SPb
  • @ YuriyPb and yes) I forgot, sorry) I added to the question - Aleksey Timoshchenko
  • All the same, the link is more convenient than dependency ... - YuriySPb
  • one
    Why not use the standard solution? - Evgeny Suetin
  • @ ЮрийСПб Юрий, but tell me how to find the link? Suppose I have a dependency in the manifest. How can I find where it is the library itself? - Aleksey Timoshchenko

1 answer 1

The source code for AccountHeader is getHeaderBackgroundView

  /** * Returns the header background view so the dev can set everything on it * * @return */ public ImageView getHeaderBackgroundView() { return mAccountHeaderBuilder.mAccountHeaderBackground; } 

Call it and assign the necessary parameters to display the picture. In your case, I think ScaleType should be assigned another one. For example centerInside