Я разработал приложение с двумя макетами (nav_header_main.xml & nav_header_main_user.xml), если вошедший в систему пользователь означает, что nav_header_main_user.xml должен отображаться, если пользователь вышел из системы nav_header_main.Я получил представление, но его не очищает каждый раз.В меню мы очистим как navigationView.getMenu().clear();
.Мне нужно знать, как очистить для заголовка навигации.
Первый XML-файл (nav_header_main.xml)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="@dimen/nav_header_height"
android:background="@color/colorPrimary"
android:gravity="bottom"
android:id="@+id/headerView"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:theme="@style/ThemeOverlay.AppCompat.Dark">
<ImageView
android:id="@+id/nav_profile_image"
android:layout_width="wrap_content"
android:layout_height="@dimen/_50sdp"
android:visibility="visible"
android:src="@drawable/splash_screen_logo"
android:layout_gravity="center" />
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/nav_round_image"
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@drawable/ic_account"
android:visibility="gone"/>
<TextView
android:id="@+id/nav_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_10sdp" />
</LinearLayout>
и второй XML-файл (nav_header_main_user.xml)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="@dimen/nav_header_height"
android:background="@color/colorPrimary"
android:gravity="bottom"
android:id="@+id/user_headerView"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:theme="@style/ThemeOverlay.AppCompat.Dark">
<TextView
android:id="@+id/player_name_after_signin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/player_name"
android:textSize="@dimen/_18sdp" />
<TextView
android:id="@+id/email_after_user_signin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/_18sdp"
android:text="@string/email_email_com" />
</LinearLayout>
мой java-код будет выглядеть так:
if( sharedpreference.getString("PlayerID",null)!=null )
{
navigationView.inflateHeaderView(R.layout.nav_header_main_user);
}
else
{
navigationView.inflateHeaderView(R.layout.nav_header_main);
}
Теперь мне не хватает кода, чтобы очистить XML-файлы в соответствии с этим.Любая помощь будет оценена