2015-12-02 12 views
5

Nachdem ich .NoActionBar im Design deklariert habe und toolbar in das Layout eingefügt habe, wird meine toolbar nicht angezeigt. Was ich am Ende bekomme, ist genau das, was man erwarten würde, wenn man keine Aktionsleiste deklariert - keine Aktionsleiste. Hier ist das Layout:AppCompat-Symbolleiste wird nicht angezeigt

activity_home.xml:

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

<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_home" 
    app:menu="@menu/activity_home_drawer"/> 

app_bar_home.xml

<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:theme="@style/AppTheme.AppBarOverlay"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     app:popupTheme="@style/AppTheme.PopupOverlay"/> 

</android.support.design.widget.AppBarLayout> 

<include layout="@layout/content_home"/> 

+3

Sie benötigen die vollständige Struktur Ihrer XML zu schaffen, nicht nur Schnipsel. Was ist der Root-Viewgroup-Typ von activity_home? Ist es ein LinearLayout? Der wahrscheinlichste Grund für Ihre Probleme hier ist, dass sowohl das '' app_bar_home'' als auch '' nav_view'' ihr 'height' Attribut auf' match_parent' gesetzt haben, so dass eines von ihnen dem Elternteil entspricht und das andere vom Bildschirm wegschiebt. –

+0

show java code .. –

Antwort

4

In Ihrer Tätigkeit Sie Ihre Symbolleiste zu initialisieren haben (wenn Sie es nicht getan haben)

Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar); 
setSupportActionBar(toolbar); 
+2

Siehe auch http://stackoverflow.com/questions/26515058/this-activity-ready-has-an-action-bar-supplied-by-the-window-decor Dies ist ein vollständigere Antwort. Diese Lösung funktioniert nicht, ohne die Stile zu fixieren. – StarWind0