2015-12-02 120 views
5

在主题中声明.NoActionBar之后,以及将toolbar置于布局中,我的toolbar未显示。我最终得到的正是你在声明没有操作栏时所期望的 - 没有操作栏。这里是布局:AppCompat工具栏未显示

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

您需要提供您的XML,不只是片段的完整结构。 “activity_home”的根视图组类型是什么?它是一个'LinearLayout'吗?这里的麻烦最可能的原因是'app_bar_home'和'nav_view'都将其'height'属性设置为'match_parent',所以它们中的一个匹配父级,并将另一个推到屏幕外。 –

+0

显示java代码.. –

回答

4

在你的活动,你必须初始化工具栏(如果你不这样做的话)

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

也看看 http://stackoverflow.com/questions/26515058/this-activity-already-has-an-action-bar-supplied-by-the-window-decor 这是一个更完整的答案。上述解决方案无法修复样式。 – StarWind0