Align one item to left of ActionBar

BSK-Team picture BSK-Team · Oct 24, 2014 · Viewed 8.1k times · Source

I want to align one item to the left of ActionBar and others to the right like this :

enter image description here

I have 5 items in my menu xml.

main.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="fr.mgs.consulting.allbrary_android.MainActivity" >

<item 
    android:id="@+id/action_spinner"
    android:showAsAction="always"
    android:actionLayout="@layout/spinner_actionbar"
    android:title="@string/action_spinner"

    android:orderInCategory="1"/>

<item 
    android:id="@+id/action_search"
    android:showAsAction="always"
    android:title="@string/action_spinner"
    android:icon="@drawable/ic_action_search"
    android:orderInCategory="2"/>

<item 
    android:id="@+id/action_tablet"
    android:showAsAction="never"
    android:title="@string/action_spinner"
    android:icon="@drawable/ic_action_tablet"
    android:orderInCategory="3"/>

<item 
    android:id="@+id/action_notifications"
    android:showAsAction="always"
    android:title="@string/action_spinner"
    android:icon="@drawable/ic_action_notifications"
    android:orderInCategory="4"/>

<item 
    android:id="@+id/action_user"
    android:showAsAction="always"
    android:title="@string/action_spinner"
    android:icon="@drawable/ic_action_user"
    android:orderInCategory="5"/>

How shall we do it? Sorry for my very bad English.

Answer

Vito picture Vito · Oct 24, 2014

You can create your own custom view for ActionBar where this left element will be like simple image view, and others menu items will be as usual menu items.

Example here: http://javatechig.com/android/actionbar-with-custom-view-example-in-android