Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - toolbar and status bar as shared objects with content changes

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

like image 852
Noa Drach Avatar asked May 18 '15 17:05

Noa Drach


People also ask

How do I show content behind the status bar?

On Android 4.1 and higher, you can set your application's content to appear behind the status bar, so that the content doesn't resize as the status bar hides and shows. To do this, use SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN . You may also need to use SYSTEM_UI_FLAG_LAYOUT_STABLE to help your app maintain a stable layout.

What is Setsupportactionbar?

It will delegate the functionalities related to your defined toolbar. It helps activity to understand the many of the requirements some of them mentioned below.

What is a status bar in Android?

Status bar (or notification bar) is an interface element at the top of the screen on Android devices that displays the notification icons, minimized notifications, battery information, device time, and other system status details.


1 Answers

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);

}
like image 139
Lennon Spirlandelli Avatar answered Oct 12 '22 22:10

Lennon Spirlandelli