AppCompat Toolbar not Showing

16,613

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

Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Share:
16,613

Related videos on Youtube

Siddharth Jaidka
Author by

Siddharth Jaidka

Updated on June 04, 2022

Comments

  • Siddharth Jaidka
    Siddharth Jaidka almost 2 years

    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
      Tim Malseed over 8 years
      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.
  • StarWind0
    StarWind0 over 7 years
    Also look at stackoverflow.com/questions/26515058/… this is a more complete answer. This solution above does not work without fixing the styles.