remove or hide header navigationView in android

拟墨画扇 提交于 2019-12-05 08:32:44
  View headerView= LayoutInflater.from(this).inflate(R.layout.drawer_header, null);
        navigationView.addHeaderView(headerView);
navigationView.getHeaderView(0).setVisibility(View.GONE);

i use dummy layout. and solved my problem but i think it is ridiculous.

If You want to remove header:

navigationView.removeHeaderView(navigationView.getHeaderView(0));

Of cource if You have more haeders You have to do this in some loop to remove them all. 0 is index of the first one.

try to add this to your style file <item name="android:windowFullscreen">true</item>

and remove app:headerLayout from navigationView xml.

and add this to your navigationView xml :

android:layout_marginTop ="@dimen/abc_action_bar_default_height_material"

it worked perfect for me.

To remove it permanently:

The Layout that contains the NavigationView widget is like this:

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header_main"
    app:menu="@menu/activity_main_drawer"/>

Just remove the app:headerLayout line from it:

    app:headerLayout="@layout/nav_header_main"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!