There are two principal ways of creating an app bar for an activity in API 21+ using the Toolbar.
Create an activity which extends AppCompatActivity and then follow the instructions here
Create a standalone
Toolbar
which acts as an app bar (define the Toolbar in xml usingandroid.support.v7.widget.Toolbar
) and then inflate a menu into it like this: ` toolbar.inflateMenu(R.menu.homeview_menu_common);
My question is: what are the benefits and drawbacks of doing one over the other?`
A related question to this topic can also be found here (How can an activity use a Toolbar without extending AppCompatActivity)
Short answer: No you should make your activity extend AppCompatActivty
You can create a toolbar without AppCompatActivty but besides an app bar the AppCompat also brings with it the support libraries that allow you to add material design to your app going as far back as API level 7 of Android.
Unless there is a specific reason for not using AppCompat all your Activites should extend AppCompatActivty to model a Material app.
You need to use an
AppCompatActivity
extendedActivity
because, when you set up theToolbar
as theActionBar
withsetSupportActionBar(Toolbar)
you get the ability to reference it throughContext.getSupportActionBar()
from nearly anywhere in your code i.eFragment
. But, if you don't extendAppCompatActivity
you can't easily get a reference to theToolbar
from anywhere else other than theActivity
in which it was defined.