Android support v23.1.0 update breaks NavigationView get/find header

后端 未结 5 643
野趣味
野趣味 2020-12-03 01:27

I have been using the v23.0.1 support library until now with no problems. Now when I switch to the new v23.1.0 library I am getting a null

5条回答
  •  遥遥无期
    2020-12-03 01:39

    It appears attaching the header view to the navigation drawer using xml is currently broken. The solution is to inflate and attach the view manually.

    activity layout

    
        app:menu="@menu/drawer_items" />
    

    Then in your code inflate and attach the header by doing the following.

    NavigationView navigationView = (NavigationView) findViewById(R.id.navigation_view);
    View drawerHeader = navigationView.inflateHeaderView(R.layout.drawer_header);
    
    TextView username = (TextView) drawerHeader.findViewById(R.id.username_textView);
    

提交回复
热议问题