Is there any way to control views inside NavigationView header?

Lạng Hoàng picture Lạng Hoàng · Jul 6, 2015 · Viewed 11.7k times · Source

As the title says, I want to know if there is any way to control views inside the NavigationView header? (Except for adding or removing header.)

For example: In the header, I have a user avatar. By default, it displays a guest image, but after the user logs in, the real avatar will be showed.

How can this be accomplished?

Answer

RmK picture RmK · Nov 17, 2015

After updating your support library to version 23.1.1 or above,

You could do this -

View header = navigationView.getHeaderView(0);
TextView text = (TextView) header.findViewById(R.id.textView);

or if you have multiple headers

navigationView.getHeaderCount()

Ref : https://code.google.com/p/android/issues/detail?id=190226#c31