我想直接通过 findViewById(R.id.nav_head_root),  findViewById(R.id.every_day_title)

来取到nav_header_main布局里面 id 为 nav_head_root  的  LinerLayout 

和  id 为 every_day_title 的  TextView ,却返回null


获取NavigationView里面headerLayout布局的部件

nav_header_main.xml  为:

获取NavigationView里面headerLayout布局的部件

直接用findViewbyid(R.id.nav_header_root),findViewById(R.id.every_day_title);返回的值是null。

我们要先获取到 Navigation ,然后通过  navigation.getHeaderView(0)  来获取  headView

接着通过headview.findViewById(R.id.nav_header_root),headview.findViewById(R.id.every_day_title);便可获取

获取NavigationView里面headerLayout布局的部件

然后就 o**k啦!

相关文章:

  • 2022-12-23
  • 2021-07-15
  • 2022-12-23
  • 2021-12-04
  • 2022-12-23
  • 2022-12-23
  • 2021-10-17
猜你喜欢
  • 2021-10-06
  • 2021-09-14
  • 2022-12-23
  • 2021-11-24
  • 2022-01-05
  • 2021-09-25
相关资源
相似解决方案