NavigationView中获取headerLayout的方法

1.获取NavigationView:

 

    private  NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);  

 

 

2.获取headerLayout

View headerLayout = navigationView.inflateHeaderView(R.layout.nav_header_main);  

 

3.获取其中的组件:

TextView res = (TextView) headerLayout.findViewById(R.id.account_show);
res.setText("dasdasdasadsasdasdasdas");

 

注意:这样或出现重复headlayout:

删除即可解决

 app:headerLayout="@layout/nav_drawer"

 

posted @ 2017-08-17 14:54  XinYiBuFang  阅读(1075)  评论(0编辑  收藏  举报