The Google+ app has a layout where it has action bar items in the main action bar and the bottom. Currently I am using android:uiOptions="splitActionBarWhenNarrow"
to place items in the bottom bar. How can I place items on both the top and bottom?

- 17,076
- 13
- 60
- 105

- 2,664
- 7
- 26
- 35
-
yes how to show overflow icon at top??? – samirprogrammer Oct 01 '13 at 18:53
5 Answers
Hope my answer is not too late for you.
- Use
android:uiOptions="splitActionBarWhenNarrow"
(this adds stuff into bottom bar). Create new layout like the below code (this layout will handle all your items on the top bar).
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="right" > <Switch android:id="@+id/switch1" android:layout_width="wrap_content" android:layout_height="match_parent"/> <ImageButton android:id="@+id/action_starred" android:layout_width="wrap_content" android:layout_height="wrap_content" style="?android:attr/actionButtonStyle" android:src="@android:drawable/ic_menu_compass" android:onClick="FakeMenu"/> </LinearLayout>
Paste this in your activity
ActionBar actionBar = getActionBar(); actionBar.setCustomView(R.layout.actionbar_top); //load your layout actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME|ActionBar.DISPLAY_SHOW_CUSTOM); //show it
That's all :)

- 17,076
- 13
- 60
- 105

- 261
- 3
- 2
-
You helped me a lot, thanks! Small remark for those who use ActionBarSherlock lib - you can get your action bar object with getSherlock().getActionBar(). – lopek Jun 01 '13 at 23:11
I don't think it is possible using the standard ActionBar. When enabling a split ActionBar, ALL actions will appear at the bottom on a narrow screen.
The bottom bar in the Google+ app's "create a post" Activity seems to be a custom implementation. Notice the long press to reveal an action's label does not work, and the bottom bar remains even when you switch to landscape orientation. The location item is a toggle switch which is also non-standard ActionBar behavior.

- 26,131
- 7
- 48
- 47
I had the same problem, nothing that i found was really working because i had to deal with the narrow of the actionbar, then on big devices, buttons were placed on top instead of bottom. So i finally solved it by placing a "footer" in the main layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="false"
android:layout_above="@+id/footer">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:id="@+id/container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/body_padding_large"
android:paddingRight="@dimen/body_padding_large"
android:paddingTop="@dimen/body_padding_medium"
android:paddingBottom="@dimen/body_padding_medium"
android:gravity="top">
</LinearLayout>
</ScrollView>
<LinearLayout android:id="@+id/footer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
style="@android:style/ButtonBar">
<Button android:id="@+id/btn_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button 1" />
<Button android:id="@+id/btn_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button 2" />
</LinearLayout>
</RelativeLayout>

- 3,777
- 4
- 30
- 49
<?xml version="1.0" encoding="utf-8"?>
< LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right" >
<Switch
android:id="@+id/switch1"
android:layout_width="wrap_content"
android:layout_height="match_parent"/>
<ImageButton
android:id="@+id/action_starred"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?android:attr/actionButtonStyle"
android:src="@android:drawable/ic_menu_compass"
android:onClick="FakeMenu"/>
</LinearLayout>
//Then put these lines of code in your java class or activity
ActionBar actionBar = getActionBar();
actionBar.setCustomView(R.layout.actionbar); //load your layout
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME|ActionBar.DISPLAY_SHOW_USTOM); //show it
// hope this helps

- 1,977
- 1
- 11
- 20
-
In that case and if you have the rights to, you can up vote that answer (If not comment is not needed). However if you found an alternative way to solve the problem, feel free to share. – TocToc Jun 15 '16 at 08:04
The bottom bar gets filled when you have more items than can be shown in the top bar.
Instead of showing the "overflow" three-dots the items will be put on the bottom bar. Remember to use the:
android:showAsAction="ifRoom|withText"
on your menu items in the XML.
Read more here: http://developer.android.com/guide/topics/ui/actionbar.html#SplitBar

- 2,299
- 1
- 22
- 29
-
That doesn't seem right. In the Google+ example, they have the overflow icon at the top as well. – PolandSpring Feb 17 '12 at 22:11
-
1