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?
All action buttons and other items available in the action overflow are defined in an XML menu resource. To add actions to the action bar, create a new XML file in your project's res/menu/ directory. The app:showAsAction attribute specifies whether the action should be shown as a button on the app bar.
To replace an app's default action bar with a Toolbar : Create a new custom theme and modify the app's properties so that it uses this new theme. Disable the windowActionBar attribute in the custom theme and enable the windowNoTitle attribute. Define a layout for the Toolbar .
The app bar, also known as the action bar, is one of the most important design elements in your app's activities, because it provides a visual structure and interactive elements that are familiar to users.
Hope my answer is not too late for you.
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 :)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With