Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to manage app bar when using fragments?

I'm using one activity as a container and multiple fragments. Some of the fragments need to display app bar, some don't while others require to show a special app bar (e.g. an app bar that shrinks when swiping up). So where should I put the app bar (or action bar), in the activity or in the fragments?

By the way, if I put the app bar inside the fragments, how should I manage the app bars properly when fragments come in or move out?

like image 662
7bitex Avatar asked Oct 31 '22 23:10

7bitex


1 Answers

if every fragment should have a different app bar, you probably want to use a Toolbar.

Toolbar is a standalone ActionBar that you can put anywhere, in any view group. The Toolbar API is roughly the same as the ActionBar one, so you should not have any major issue migrating to Toolbar.

For your app, you should have Toolbar in every fragment, when needed and every fragment control it's own Toolbar.

like image 75
pdegand59 Avatar answered Nov 15 '22 05:11

pdegand59