9

In my app I set the toolbar and status bar as shared objects as suggested in option #2 in this post

The general behavior and outline of the toolbar and tabs are excellent - the only issue is that when I move to activity B, some of the UI elements of the Toolbar are not participating in the content transition, particularly the Toolbar title and the menu icons.

I tried adding a SharedElementCallback and in it to loop over the children of the toolbar and tabs and add them all to a Fade transition - but it didn't affect the behaviour of the toolbar and tab content.

Any idea how to proceed from here? The desired effect is to have the elements of the Toolbar (title, up button, menu icons) participate in the content transition.

Added screenshots after comment:

Activity A

In Activity A

Activity B

In Activity B

Acadian_Ghost
  • 238
  • 3
  • 15
Noa Drach
  • 2,381
  • 3
  • 26
  • 44
  • elaborate sir, changing how, can you give screenshots? – Elltz Jun 02 '15 at 02:51
  • What is your desired behaviour? "*when I move to activity B some of the text and icons are changing*" - activities should independent components of your application why should it's text and/or icons change when switching to the activity? – Simas Jun 02 '15 at 13:45
  • what I want is a smooth transition in the toolbar from Activity A to B - meaning some fade out of the icons and text presented in A and fade in of the icons and text presented in B. Currently the background is transitioning ok but the text and icons switch when the animation completes – Noa Drach Jun 02 '15 at 13:54

1 Answers1

1

Each activity has your own menu, so you have to create the menu for each one, even if they are the same.

However, if you prefer, you can create just one menu and create a custom class for manipulate the menu; Then you call this custom class on onCreateOptionsMenu and onOptionsItemSelected from whatever activity.

The following code is an example.

Custom class:

public class MenuActionBar {

    public static void createOptionsMenu(final Activity activity, Menu menu) {

        activity.getMenuInflater().inflate(R.menu.yourmenu, menu);

        // Do whatever you wanna do

    }

    public static boolean optionsItemSelected(Activity activity, MenuItem item) {

        // Do whatever you wanna do

    }

}

Activity:

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    MenuActionBar.createOptionsMenu(this, menu);

    return super.onCreateOptionsMenu(menu);

}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    return MenuActionBar.optionsItemSelected(this, item)
            ? true : super.onOptionsItemSelected(item);

}
Lennon Spirlandelli
  • 3,131
  • 5
  • 26
  • 51
  • The question is how to animate the transition from one menu to the other – Noa Drach Jun 02 '15 at 14:07
  • But you said it's working well, and the only issue is the icons and texts that change. Try to put your animation code into the custom class. – Lennon Spirlandelli Jun 02 '15 at 14:32
  • they change without animation - the part that is working ok is the part where the entire toolbar isn't flickering - which is the issue that was addressed in the post I linked to – Noa Drach Jun 02 '15 at 15:02