Skip to content Skip to sidebar Skip to footer

Split Action Bar On Android 5.0 (Lollipop)

Does anybody know if the split action bar when narrow feature was removed from Android 5.0? It seems that it does not have any effect on the layout anymore.

Solution 1:

Since this question was not really answered before...

Does anybody know if the split action bar when narrow feature was removed from Android 5.0?

Yes, it was, though that change is not documented outside of the issue tracker entry itself.


Solution 2:

As said you cannot split the action bar, although you can achieve a even better result with the Toolbar.

   Toolbar toolbarBottom = (Toolbar) findViewById(R.id.toolbar_bottom);
    toolbarBottom.inflateMenu(R.menu.menu_bottom);
    toolbarBottom.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            //your code
            return false;
        }
    });

It's important to say that this feature is backwards compatible with the appcompat support

compile "com.android.support:appcompat-v7:21.0.+"

You'll also need to declare the toolbar in your layout.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<android.support.v7.widget.Toolbar xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary"
    android:minHeight="?attr/actionBarSize"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar_bottom"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:background="?attr/colorPrimary"
    android:minHeight="?attr/actionBarSize"/>

    <LinearLayout
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="?attr/actionBarSize"
    android:layout_above="@id/toolbar"
    android:layout_below="@id/toolbar_bottom" />
</LinearLayout> 


Solution 3:

Like other answers you can create your own bars with menu xml files or directly from coding.
Toolbar won't set two or more items visible always, but you can force the toolbar to show to action buttons visible always and overflow actions will create a options menu automatically.
Other basic customisation can be done by xml files.
Code:

 final Toolbar lowerTool=(Toolbar)findViewById(R.id.lower_toolbar);
        lowerTool.inflateMenu(R.menu.lower_toolbar_menu);
        lowerTool.getMenu().findItem(com.tvf.emag.R.id.action_previous).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT| MenuItem.SHOW_AS_ACTION_IF_ROOM);
        lowerTool.getMenu().findItem(com.tvf.emag.R.id.action_previous).setEnabled(mPager.getCurrentItem() > 0);
        lowerTool.getMenu().add(Menu.NONE, com.tvf.emag.R.id.action_next, Menu.NONE,
                (mPager.getCurrentItem() == mPagerAdapter.getCount() - 1)
                        ? com.tvf.emag.R.string.action_finish
                        : com.tvf.emag.R.string.action_next);
        lowerTool.getMenu().findItem(com.tvf.emag.R.id.action_next).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT| MenuItem.SHOW_AS_ACTION_IF_ROOM);
        lowerTool.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem menuItem) {
                switch (menuItem.getItemId()) {
                    case com.tvf.emag.R.id.action_previous:
                        mPager.setCurrentItem(mPager.getCurrentItem() - 1);
                        return true;
                    case com.tvf.emag.R.id.action_next:
                        mPager.setCurrentItem(mPager.getCurrentItem() + 1);
                        return true;
                }
                return true;
            }
        });

Post a Comment for "Split Action Bar On Android 5.0 (Lollipop)"