2

I am new to android development and I was wondering how can I can create three evenly spaced buttons on the action bar and make sure that they fill up the whole action bar.

The code I have written so far

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+id/action_groups"
        android:showAsAction="always"
        android:title="@string/action_groups" />
    <item
        android:id="@+id/action_list_of_contacts"
        android:showAsAction="always"
        android:title="@string/action_listOfContacts"/>
    <item
         android:id="@+id/action_favourites"
         android:showAsAction="always"
         android:title="@string/action_favourites" />
</menu>
user123456
  • 2,287
  • 3
  • 13
  • 10

1 Answers1

2

You can do it by using setCustomView()

this is the sample layout (sp.xml)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
 >

<Button 
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="button1"
/>

<Button 
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="button1"
/>
<Button 
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="button1"
/>

</LinearLayout>

And in the activity after setContentView do this

getActionBar().setHomeButtonEnabled(false); getActionBar().setDisplayShowCustomEnabled(true); getActionBar().setCustomView(R.layout.sp);

prijupaul
  • 2,076
  • 2
  • 15
  • 17