For me other Answers didn't work.
I have tried the below code.
I know it's too late. Hope this will help some.
What I did to access the view of header.
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
View headerview = navigationView.getHeaderView(0);
TextView profilename = (TextView) headerview.findViewById(R.id.prof_username);
profilename.setText("your name")
for clicking the views of header, here I have used a linearlayout of headerview
LinearLayout header = (LinearLayout) headerview.findViewById(R.id.header);
header.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(HomeActivity.this, "clicked", Toast.LENGTH_SHORT).show();
drawer.closeDrawer(GravityCompat.START);
}
});
Or
headerview.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Your code here
}
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…