Delete or hide Android navigation header

I am using project 23.1.1 in my project. I want a box without a header. enough menu items. I am not adding any header (programmatically or in XML). but in the box I have an empty headline. please help me how to remove this empty header.

<android.support.design.widget.NavigationView android:id="@+id/navigation_view" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="right" app:menu="@menu/drawer" /> 
+5
source share
4 answers
  View headerView= LayoutInflater.from(this).inflate(R.layout.drawer_header, null); navigationView.addHeaderView(headerView); navigationView.getHeaderView(0).setVisibility(View.GONE); 

I am using a dummy layout. and solved my problem, but I think it's funny.

+5
source

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

and remove app:headerLayout from navigationView xml.

and add this to your xml navigation element:

 android:layout_marginTop ="@dimen/abc_action_bar_default_height_material" 

It worked perfect for me.

0
source

If you want to remove the header:

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

Course, if you have more bindings, you need to do this in some kind of loop to remove them all. 0 is the index of the first.

0
source

To remove it permanently:

The layout containing the NavigationView widget is as follows:

 <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 line: headerLayout from it:

  app:headerLayout="@layout/nav_header_main" 
-1
source

Source: https://habr.com/ru/post/1237002/


All Articles