I customize the toolbar in my main activity, and when I go inside the fragment, I want to add a slider to it. If I had access to the Toolbar object, I would simply do:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayShowTitleEnabled(false); Spinner mNavigationSpinner = new SpinnerTrigger(getSupportActionBar().getThemedContext()); toolbar.addView(mNavigationSpinner);
But if I get it with
((ActionBarActivity) getActivity()).getSupportActionBar()
I don't have addView() method. So my question is how can I add a view to a toolbar in a fragment if the toolbar itself was created in Activity.
I'm not sure if this is the best look at this, but I don’t think I can use Spinner in the layout because most of my snippets don’t use it, they just set the title on the toolbar. But at the same time, it would be great if I could define the toolbar once in the main action, and not repeat it for each fragment.
Limon source share