Using the toolbar in a snippet or in action

I am using the Android-ObservableScrollView library. Everything works fine, but I have activity to store fragments, so all views are encapsulated in a fragment. In activity there is only FrameLayout for storing fragments.
Therefore, I need to use the Toolbar in my application, I have several ideas on how to implement this.

  • Use the toolbar in action, in this case my layout will have a FrameLayout and a toolbar. This way, I get in touch with activity, when I need to do something with the toolbar, I can also get it using getSupportedActionBar() from the fragment.

  • Use the toolbar inside the fragment (in your layout) when creating each fragment. And every time I change a fragment, I have to add a new toolbar to this activity. In some fragment I will have different toolbars, but not in all. This is a good approach to store a toolbar inside a fragment.

The problem that I see when using the second approach, if there is more than one fragment on the screen, there will also be several toolbars.

Please suggest what the correct path will be in this case.
Thanks.

+6
source share
1 answer

You must use the first method. Using the first method will have less problems than the second, because in the second method you have to define the toolbar many times, which is not good programming.

0
source

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


All Articles