wealthfront / magellan

The simplest navigation library for Android.
Apache License 2.0
677 stars 72 forks source link

Add help/example on how to work with Toolbar, menu and back button on Toolbar #28

Open dimparf opened 7 years ago

dimparf commented 7 years ago

Thanks for great and simple library. How to work with Toolbar menu and back button on Toolbar?

fabiendevos commented 7 years ago

Hi @dimparf ,

Thanks for your kind words! To work with the Toolbar, simply add one in your activity xml ad set it up like you would normally do, then you can set a NavigationListener and implement onNavigate(ActionBarConfig actionBarConfig) to manipulate the toolbar. You can also use onUpdateMenu() on a screen to update the menu.

We hope to do some of this for you eventually, but this way, you have full control.

This definitely need some more documentation / example.

Hope this answer your question,

Fabien

dimparf commented 7 years ago

Thanks @fabiendevos

dimparf commented 7 years ago

@fabiendevos My activity xml contains ScreenContainer as root. Where should I add a toolbar?

fabiendevos commented 7 years ago

You can wrap it in a LinearLayout and add the Toolbar on top of the ScreenContainer for example. The ScreenContainer is where the swapping of the Screen's Views will happen.

dimparf commented 7 years ago

@fabiendevos But if I doing it @Override public String getTitle(Context context) { return context.getResources().getString(R.string.main_screen_title); } not working (title not showing and changing by change screen).

fabiendevos commented 7 years ago

True: you also need to set your toolbar as the Action Bar by using: http://developer.android.com/reference/android/support/v7/app/AppCompatActivity.html#setSupportActionBar(android.support.v7.widget.Toolbar)

fabiendevos commented 7 years ago

Definitely need some more examples / helper code

wclausen commented 7 years ago

I added a page to the wiki for working with the action bar that should help you get set up.

Also check out the changes in #34

OmarCantuariasSaleh commented 7 years ago

@wclausen It does not for me, I followed the instructions in the wiki page but I can't get it to work, I get a 'Cannot resolve method setActionBarColor', the same with showActionBar and hideActionBar. Am I supposed to create the methods myself? Am I missing some import? I'm not very experienced and I'm finding the wiki pages to be very vague.Please help.

felipebelluco commented 7 years ago

In this case, with the class extending AppCompatActivity, where exactly do I have to call:

Navigator.withRoot(HomeScreen()).build()

Obs.: I'm using Kotlin.

fabiendevos commented 7 years ago

@felipebelluco : are you using SingleActivity? Did you look at the wiki page Working With The Action Bar and at this code: #34 ?

fabiendevos commented 7 years ago

@OmarCantuariasSaleh try to look at the advanced sample and at this code: #34

felipebelluco commented 7 years ago

@fabiendevos no because the wiki Ensure your Activity extends AppCompatActivity says to use AppComparActivity.

fabiendevos commented 7 years ago

@felipebelluco yes, for now, you need to basically copy he code of SingleActivity and maye it inherit from AppCompatActivity, something like that: https://github.com/wealthfront/magellan/blob/f16857e4aebab9752c9df4d85f7295e6327e2abf/magellan-sample-advanced/src/main/java/com/wealthfront/magellan/sample/advanced/MainActivity.java

(in this example, the Navigator is injected as a singleton, but you can simply keep it in a static field to achieve the same result without the need for dependency injection)