Fabian
Fabian

Reputation: 2713

Gmail tablet like Actionbar items

I'm trying to build an app with a split actionbar/toolbar like in the Gmail app.

Is there any view element for this behaviour or do I have to write such a toolbar myself?

The search icon is moving with the master fragment when opening the slidingDrawer.

Closed drawer

Opened drawer

Upvotes: 12

Views: 1109

Answers (1)

MrEngineer13
MrEngineer13

Reputation: 38856

To accomplish this you can add one of the new Toolbar widgets to each of your fragments layouts. The new Toolbar class was designed to be much more flexible than a traditional Actionbar and will work well in this split design. This post is a good overview for implementing a standalone Toolbar. For posterity's sake I've included the sample code for it below.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.blah);

    Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);

    // Set an OnMenuItemClickListener to handle menu item clicks
    toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
        // Handle the menu item
        return true;
        }
    });

    // Inflate a menu to be displayed in the toolbar
    toolbar.inflateMenu(R.menu.your_toolbar_menu);
}

Upvotes: 2

Related Questions