K
K
kirawa2017-10-04 13:35:07
Android
kirawa, 2017-10-04 13:35:07

How to make a dynamic toolbar and implement it in one place?

Good afternoon, I have one activity with a contentMain that is filled with fragments. Is it possible somehow in the main activity to track changes in the life cycle so that in one place the toolbar can be changed dynamically, for example like this:

public static void dynamicToolbar(Activity activity){
        Fragment fragment =  activity.getFragmentManager().findFragmentById(R.id.contentMain);
        Toolbar toolbar  = activity.findViewById(R.id.toolbar);
        if (fragment instanceof GoodsInfoFragment){
            toolbar.setTitle("Информация о товаре");
        }else if(fragment instanceof GoodsFragment){
              //dosomething();
        }
    }

Maybe there are other solutions?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question