What is the difference between a Toolbar and another view?

Asked

Viewed 68 times

3

I’m learning to use the toolbar on Android development and saw that the use of it is very similar to other views, I saw that you can put it without being at the top, that you can put items inside it (button for example), like a layout, then hit the doubt, I can use a LinearLayout (or other) as a toolbar?
Put it on top, set colors, put items, etc... What are the benefits of using Toolbar even?

1 answer

3


Toolbar is indeed a type of View, more properly a type of Viewgroup:

java.lang.Object
   ↳    android.view.View
       ↳    android.view.ViewGroup
           ↳    android.support.v7.widget.Toolbar 

As you can see in his hierarchy, he inherits the characteristics of View and Viewgroup.
That is why it is possible to do all that you enumerate in the question.

However, Toolbar is much more than a Viewgroup.
He adds other features in order to be a alternative to Actionbar.

Among them,

  • Navigation button.
  • Logo.
  • Title and subtitle.
  • Include other views.
  • Action menu.
  • But in a Layout (like Linear by example, which is what I use most) it is not possible to do all this? If so, why use a Toolbar? by already being created properly for this and being simpler?

  • 1

    Yes it is possible. At the bottom is what was done by those who made the Toolbar, started from a Viewgroup. What is the reason for you to do what is already done?

  • Oh I understood then, thank you very much there, it was a simple doubt, but now it’s all ok, now I go back to the codes!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.