7

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.

Florian
  • 2,048
  • 3
  • 28
  • 36
  • 5
    you provide a bottom and top toolbar now, not the system – tyczj Oct 30 '14 at 18:24
  • how do we do this for backwards compatibility? When taget SDK is 21 and appcompat library is also at level 21, system splits the actionBar, but i see all the action items crammed at the top, with an empty white strip at bottom. – iTapAndroid Nov 10 '14 at 23:01
  • 2
    As far as I have seen, you need to implement a toolbar which you place on bottom. Should not be a big issue. What I could not yet figure out because I had too little time is to evenly distribute the icons on the action bar. – Florian Nov 11 '14 at 17:21

3 Answers3

9

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.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
3

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> 

Tin Megali
  • 771
  • 5
  • 25
0

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;
            }
        });
bummi
  • 27,123
  • 14
  • 62
  • 101
Viroj Fernando
  • 461
  • 4
  • 8