Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 897
Fabian Avatar asked Jul 02 '15 10:07

Fabian


1 Answers

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);
}
like image 200
MrEngineer13 Avatar answered Nov 19 '22 05:11

MrEngineer13