1
私は2つのxmlヘッダーファイルを持っています。私はそれらのうちの1つをユーザーログインの前に表示し、別のヘッダーをログイン後に表示します。ナビゲーションビューで2つのヘッダーxmlファイルを変更する方法は?
共有の設定でログインの状態を確認していますが、ヘッダーxmlファイルを変更する方法がわかりません。
私は2つのxmlヘッダーファイルを持っています。私はそれらのうちの1つをユーザーログインの前に表示し、別のヘッダーをログイン後に表示します。ナビゲーションビューで2つのヘッダーxmlファイルを変更する方法は?
共有の設定でログインの状態を確認していますが、ヘッダーxmlファイルを変更する方法がわかりません。
一つの方法は、現在のヘッダビュー(removeHeaderView)を取り外し、新しいものを膨らませると、このような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);
HIH
完璧に動作します
私が最後に変更しますあなたのソリューションのラインは、次のようになります navigationView.inflateHeaderView(R.layout.nav_my_other_header); ありがとう –