2016-05-02 29 views
2

Ich arbeite an einer Android App und es erfordert DrawerLayout unter der ToolBar. Ich habe das erreicht, aber NavigationView Header, d. H. Status Bar 24dp ist sichtbar, auch nach dem Entfernen der Kopfzeile. Gibt es eine Möglichkeit, das zu entfernen?Android ausblenden NavigationView Header

Problem

XML-Datei:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    > 

    <include 
     layout="@layout/app_bar_home" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"/> 

    <android.support.v4.widget.DrawerLayout 
     android:layout_marginTop="?android:attr/actionBarSize" 
     android:id="@+id/drawer_layout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     > 

     <android.support.design.widget.NavigationView 
      android:paddingBottom="0dp" 
      android:id="@+id/nav_view" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_gravity="start" 
      app:headerLayout="@null" 
      app:menu="@menu/activity_home_drawer"/> 

    </android.support.v4.widget.DrawerLayout> 
</RelativeLayout> 

Antwort

1

entfernen app:headerLayout="@null" von Ihrem navigationview.

pumpen Sie Ihr headerlayout von onCreate() so auf, und setzen Sie dann die Sichtbarkeit weg.

View headerView= LayoutInflater.from(this).inflate(R.layout.drawer_header, null); 
navigationView.addHeaderView(headerView); 
navigationView.getHeaderView(0).setVisibility(View.GONE); 
+0

Bereits versucht, kein Glück. Übrigens siehst du den oberen grauen Balken in der Schublade. Das ist das Problem. Wie kann ich es durchscheinend machen? – Max

+0

Hatten Sie die Hintergrundfarbe des Header-Layouts auf transparent geändert? –

+0

Wird es einen Unterschied machen? Sogar wir setzen Sichtbarkeit auf Gone? – Max

0

definieren Gruppen in Menü und dann die Gruppe verstecken mit:

navigationView.getMenu().setGroupVisible(groupPosition, false); 

Entfernen Sie auch headerLayout Attribué.

1

versuchen diese:

View headerView = navigationView.inflateHeaderView(R.layout.nav_header_home); 

headerView.setVisibility(View.GONE); 

und die Linie App entfernen: headerLayout = "@ null" aus dem xml.

1

Auch wie diese versuchen,

<android.support.v4.widget.DrawerLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/drawer_layout" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<!-- Framelayout to display Fragments --> 
<FrameLayout 
    android:id="@+id/frame_container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 

<!-- Listview to display slider menu --> 
<ListView 
    android:id="@+id/list_slidermenu" 
    android:layout_width="240dp" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:choiceMode="singleChoice" 
    android:divider="@color/list_divider" 
    android:dividerHeight="1dp"  
    android:background="@color/list_background"/> 

1

Wahrscheinlich, weil die Höhe ist nicht genug. Warum benutzen Sie nicht wrap_content mit layout="@layout/app_bar_home" und fügen android:layout_below zu Ihrem DrawerLayout hinzu?
Oder um es einfach zu halten, können Sie in diesem Fall auch LinearLayout verwenden. Es wäre einfacher:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    > 

    <include 
     layout="@layout/app_bar_home" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"/> 

    <android.support.v4.widget.DrawerLayout 
     android:id="@+id/drawer_layout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     > 

     <android.support.design.widget.NavigationView 
      android:paddingBottom="0dp" 
      android:id="@+id/nav_view" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_gravity="start" 
      app:headerLayout="@null" 
      app:menu="@menu/activity_home_drawer"/> 

    </android.support.v4.widget.DrawerLayout> 
</LinearLayout> 
Verwandte Themen