NavigationView findViewById can't find header view

在最新的android support library, (23.1.0)中,NavigationView中的headerlayout里,view不能找到,返回的是null,但是在这版本之前确实可以的,在google+上找到了原因:

Ian Lake
2015年10月16日
  1
 
Follow along on  https://code.google.com/p/android/issues/detail?id=190226 - NavigationView moved to a RecyclerView based approach, meaning the header is now added as one type of row in the Adapter. That also means that it isn't immediately available in the view hierarchy.

所以,变通的方案有:

View headerView = navigationView.inflateHeaderView(R.layout.navigation_header);
headerView.findViewById(R.id.navigation_header_text);

链接:
https://code.google.com/p/android/issues/detail?id=190226 点击打开链接

你可能感兴趣的:(NavigationView findViewById can't find header view)