NavigationView中获取headerLayout实现点击事件的方法

来源:互联网 发布:linux 查看中间几行 编辑:程序博客网 时间:2024/06/06 07:30

特别简单,总共分三步:

第一步:

获取NavigationView

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

第二步:

获取headerLayout

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

第三步:

获取其中的组件:

  1. head = (ImageView) headerLayout.findViewById(R.id.Iamge_mine_head);  
  2. myName = (TextView) headerLayout.findViewById(R.id.Tview_mine_myName);  

这样会出现一个问题



如下:只需要将xml中的

  1. app:headerLayout="@layout/nav_header_main"  
删除即可,当然获取其组件的时候可以利用如下获取派生到我的代码片
  1. View headerView = navigationView.getHeaderView(0);  
0 0