2016-05-02 2 views
2

Я работаю над приложением для Android и требует DrawerLayout ниже ToolBar. Я достиг этого, но заголовок NavigationView i.e Status Bar 24dp отображается даже после удаления заголовка. Есть ли способ удалить это?Android hide NavigationView header

Problem

XML файл:

<?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> 

ответ

1

Удалить app:headerLayout="@null" из вашего navigationview.

надуть свой заголовок из onCreate() следующим образом, а затем установить видимость.

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

Уже пробовал, не повезло. Кстати, вы видите верхнюю серую полосу в ящике. Это проблема. Как я могу сделать его полупрозрачным? – Max

+0

Вы изменили цвет фона заголовка на прозрачный? –

+0

Разве это будет другое? Даже мы настраиваем видимость на Gone? – Max

0

Определение групп в меню, а затем скрыть группу с помощью:

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

Кроме того, удалить headerLayout Attribué.

1

попробовать это одно:

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

headerView.setVisibility(View.GONE); 

и удалить приложение линии: headerLayout = "@ нуль" из вашего XML.

1

Также попробуйте, как это,

<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

Вероятно потому, что высота не достаточно. Почему бы вам не использовать wrap_content с layout="@layout/app_bar_home" и добавить android:layout_below в ваш DrawerLayout?
Или для упрощения, вы также можете использовать LinearLayout в этом случае. Было бы проще:

<?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> 
Смежные вопросы