Android Split Action Bar with Action Items on the top and bottom?
Asked Answered
P

5

57

Is there a way to specify some action items to the top part of the Split Action Bar while the others go to the bottom? Or is it all or nothing, whereby all the action items go to the bottom part of the split only?

enter image description here

Pentacle answered 20/12, 2011 at 6:50 Comment(0)
P
26

This is currently not possible.

See the response directly from Android developers Reto Meier and Roman Nurik during the Android Developer Office Hours: http://youtu.be/pBmRCBP56-Q?t=55m50s

Pentacle answered 22/12, 2011 at 20:5 Comment(2)
Hi @RyanR, how about now in 2014?Swarth
@fuzzybee no not to my knowledge. This is an Android design consideration rather than a code limitation.Pentacle
V
17

To solve this I used a custom view as my action bar:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    ActionBar actionBar = getActionBar();
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);

    View view = View.inflate(getApplicationContext(), R.layout.actionbar,
            null);
    actionBar.setCustomView(view);

}

and then for the bottom bar I inflated my menu view or whatever you want to appear at bottom:

 @Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.browser_main, menu);
    RelativeLayout relativeLayout = (RelativeLayout) menu.findItem(
            R.id.layout_item).getActionView();

    View inflatedView = getLayoutInflater().inflate(
            R.layout.media_bottombar, null);

    relativeLayout.addView(inflatedView);

    return true;
}

In the Android Manifest, I also include (android:uiOptions="splitActionBarWhenNarrow") like this:

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"
    android:uiOptions="splitActionBarWhenNarrow" > ....
Ventura answered 5/12, 2012 at 5:37 Comment(0)
F
14

I solved this problem by using a CustomView and adding the menu items, which should display at the top, to this view.

Fingerling answered 21/12, 2011 at 8:47 Comment(1)
How exactly did you do this?Anthologize
G
1

Doubtful. However, you could se a combination of these when creating your menu items in the Action Bar to experiment.

MenuItem.SHOW_AS_ACTION_ALWAYS
MenuItem.SHOW_AS_ACTION_NEVER
MenuItem.SHOW_IF_ROOM
Glossography answered 21/12, 2011 at 1:30 Comment(0)
S
1

If this option is activated, Android has the option to split the action bar. Whether to split is decided by the system at runtime

You can define that the action bar should be automatically split by the system if not enough space is available you can activate this via the android:uiOptions="SplitActionBarWhenNarrow" parameter in the declaration of your application activity in the AndroidManifest.xml file.

Surgeonfish answered 3/2, 2015 at 7:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.