Search code examples
androidnavigationview

Is there any way to control views inside NavigationView header?


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?


Solution

  • 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