How do I access setSupportActionBar(Toolbar toolbar)
inside FragmentActivity
? I can't access it inside FragmentActivity
toolbar = (Toolbar) findViewById(R.id.search_bar); setSupportActionBar( toolbar);
When using fragments, the app bar can be implemented as an ActionBar that is owned by the host activity or a toolbar within your fragment's layout. Ownership of the app bar varies depending on the needs of your app.
getActivity()). getToolbar(); will be the right answer!! for getting the Toolbar in fragment!!
Asking for help, clarification, or responding to other answers.
In Android applications, Toolbar is a kind of ViewGroup that can be placed in the XML layouts of an activity. It was introduced by the Google Android team during the release of Android Lollipop(API 21). The Toolbar is basically the advanced successor of the ActionBar.
With the latest version of the support library you should make your Activity extend AppCompatActivity
as ActionBarActivity
has been deprecated.
It provides the same functionality as your ActionBarActivity previously did. You shouldn't need to make any further changes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With