I have used navigation view in my app. Header in navigation view is repeated twice but i actually removed it (app:headerLayout="@layout/header") in xml. And i wanna implement action(like as button) from header of navigation view.
In code i have written like this
mNavigationView = (NavigationView) findViewById(R.id.navigation_view);
headerView = mNavigationView.inflateHeaderView(R.layout.bp_header);
googele_plus = (ImageButton) headerView.findViewById(R.id.google_p);
facebook = (ImageButton) headerViewfindViewById(R.id.fb);
Header likes below
I got NullPointerException error if headerView removed from image button Any suggestion or solution would be grateful
Update your support library to 23.1.1 or above.
After which you can do this -
Add the headerview in the app:headerLayout="@layout/header" inside NavigationView.
Then, you can access it by,
mNavigationView = (NavigationView) findViewById(R.id.navigation_view);
View headerView = mNavigationView.getHeaderView(0)
googele_plus = (ImageButton) headerView.findViewById(R.id.google_p);
facebook = (ImageButton) headerView.findViewById(R.id.fb);
Ref : https://code.google.com/p/android/issues/detail?id=190226#c31