Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AppCompat Toolbar not Showing

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

like image 788
Siddharth Jaidka Avatar asked Dec 02 '15 03:12

Siddharth Jaidka


People also ask

What is Androidx Appcompat widget toolbar?

androidx.appcompat.widget.Toolbar. A standard toolbar for use within application content. A Toolbar is a generalization of action bars for use within application layouts.

How to customize appbar in android studio?

This example demonstrate about how to create a custom action bar in Android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.

What is the difference between a toolbar and an Action bar?

The Toolbar is basically the advanced successor of the ActionBar. It is much more flexible and customizable in terms of appearance and functionality. Unlike ActionBar, its position is not hardcoded i.e., not at the top of an activity.


1 Answers

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

Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
like image 55
farhan patel Avatar answered Sep 17 '22 15:09

farhan patel