我有两个 xml 头文件,我想在用户登录前显示其中一个,在登录后显示另一个。
我正在通过共享首选项检查登录状态,但我不知道如何更改 header xml 文件。
最佳答案
一种方法是删除当前标题 View (removeHeaderView) 并填充新的标题 View 并将其设置为 NavigationView
(inflateHeaderView),如下所示:
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
// If the view has not been set in the xml then here should be a null check because there is going to be no header view
// and there will be no need to remove that
View hView = navigationView.getHeaderView(0);
navigationView.removeHeaderView(hView);
navigationView.inflateHeaderView(R.layout.nav_my_other_header);
高
关于java - 如何在导航 View 中的 2 个 header xml 文件之间切换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48027489/