Android – Customising NavigationView – Adding dynamic headerView, Android Support Design Library


I tried the navigationView from the new android support design library. I want to have a dynamic headerview. Basically, my headerview will show something like quote of the day. I have like around 10 quotes and i want to randomly select a quote and display in a textview in the headerView. I also want to add onClick method for the headerView.

Right now, I don't see any possibilities of changing the headerview layout programmatically. Any suggestions to implement this?

Best Solution

first create header XML like lay_header.xml

    android:layout_height="wrap_content" />

on your java file inflate this above header in a TextView. like

TextView headerView = (TextView) LayoutInflater.from(this).inflate(R.layout.lay_header, null);

Now add it as a HeaderView

navView = (NavigationView) findViewById(;

Thats it...