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);
Related videos on Youtube
Author by
Siddharth Jaidka
Updated on June 04, 2022Comments
-
Siddharth Jaidka almost 2 years
After declaring .NoActionBar in the theme, as well as putting the
toolbar
in the layout, mytoolbar
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 over 8 yearsYou need to provide the full structure of your xml, not just snippets. What is the root viewgroup type of
activity_home
? Is it aLinearLayout
? The most likely cause of your trouble here is that both theapp_bar_home
andnav_view
have theirheight
attribute set tomatch_parent
, so one of them is matching the parent and pushing the other one off screen.
-
-
StarWind0 over 7 yearsAlso look at stackoverflow.com/questions/26515058/… this is a more complete answer. This solution above does not work without fixing the styles.