Why should I use AppCompatActivity instead of a standalone toolbar to create an Activity application bar?

There are two main ways to create an application bar to work in API 21+ using the toolbar.

  • Create an action that extends AppCompatActivity, and then follow the instructions here

  • Create a standalone Toolbarthat acts like an application bar (define a toolbar in xml with android.support.v7.widget.Toolbar), and then run the menu in it as follows: `toolbar.inflateMenu (R.menu.homeview_menu_common);

My question is: what are the advantages and disadvantages of one of them?

A related question can also be found here ( How can an application use a toolbar without the AppCompatActivity extension )

+4
source share
2 answers

Short answer : no, you have to activate your AppCompatActivty activity

You can create a toolbar without AppCompatActivty, but in addition to the application panel, AppCompat also provides support libraries that allow you to add material design to your application, starting from API level 7 on Android.

Unless you have a specific reason not to use AppCompat, all your actions should extend AppCompatActivty to model the Material application.

+2
source

AppCompatActivity extended Activity, , Toolbar ActionBar setSupportActionBar(Toolbar), Context.getSupportActionBar() , .. Fragment. AppCompatActivity, Toolbar , Activity, .

0

Source: https://habr.com/ru/post/1613766/


All Articles