我在我的应用程序中使用了导航视图。导航视图中的标题重复出现了两次,但实际上我已经在xml中删除了它(app:headerLayout="@layout/header")。我想要从导航视图的标题实现操作(例如按钮)。
在代码中,我像这样编写:
mNavigationView = (NavigationView) findViewById(R.id.navigation_view);
headerView = mNavigationView.inflateHeaderView(R.layout.bp_header);
googele_plus = (ImageButton) headerView.findViewById(R.id.google_p);
facebook = (ImageButton) headerViewfindViewById(R.id.fb);
头部如下所示
如果从图像按钮中删除headerView,则会出现NullPointerException错误 任何建议或解决方案将不胜感激