11

After declaring .NoActionBar in the theme, as well as putting the toolbar in the layout, my toolbar does not show. What I end up getting is exactly what you'd expect when declaring no action bar -- no action bar. Here is the layout:

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"/>

Tim Malseed
  • 6,003
  • 6
  • 48
  • 66
Siddharth Jaidka
  • 111
  • 1
  • 1
  • 4
  • 5
    You need to provide the full structure of your xml, not just snippets. What is the root viewgroup type of `activity_home`? Is it a `LinearLayout`? The most likely cause of your trouble here is that both the `app_bar_home` and `nav_view` have their `height` attribute set to `match_parent`, so one of them is matching the parent and pushing the other one off screen. – Tim Malseed Dec 02 '15 at 04:31
  • I dont fully understand. After declaring .NoActionBar, why do you expect your toolbar to be shown? I always do this to remove my toolbar –  Feb 18 '20 at 19:10

1 Answers1

11

In your activity you have to initialize your toolbar(if you've not done it)

Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
farhan patel
  • 1,490
  • 2
  • 19
  • 30
  • 6
    Also look at http://stackoverflow.com/questions/26515058/this-activity-already-has-an-action-bar-supplied-by-the-window-decor this is a more complete answer. This solution above does not work without fixing the styles. – StarWind0 Sep 19 '16 at 20:38