S
S
Saveli Tomak2017-05-13 21:59:49
Java
Saveli Tomak, 2017-05-13 21:59:49

How to dynamically change the Toolbar when working with fragments?

Hello. For a little bit I'm trying to delve into android development. I am making a case app.
There is a single activity, one of the fragments is the application menu, by clicking on each of the items in place of the "menu" fragment, another fragment opens with its own toolbar. Each toolbar differs from the others in its title and pop-up menu, in fact, how to do it more competently from the point of view of architecture (or is the option with one activity a priori considered incorrect)?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Boris K., 2017-05-18
@kaftanati

In activation during initialization:

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
if (toolbar != null){
    toolbar.setTitle(...);
    setSupportActionBar(toolbar);
    ...
}

In the snippet on initialization:
Toolbar toolbar = (Toolbar) getActivity().findViewById(R.id.toolbar);
if (toolbar != null)
   toolbar.setTitle(...);
   ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question