2

I am using ActionbarSherlock library to implement action bar for Android 2.1 API 7 platform. The Sherlock library is imported to my own project successfully.

Then, in my project, I have res/menu/action_menu.xml :

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/test1"
          android:title="@string/test_1"
          android:showAsAction="ifRoom"
          />    
    <item android:id="@+id/test2"
          android:title="@string/test_2"
          android:showAsAction="ifRoom"
          />
</menu>

My Activity:

import android.support.v4.app.ActionBar;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.Menu;
import android.support.v4.view.MenuItem;

public class MyActivity extends FragmentActivity {

     @Override
     protected void onStart() {
      super.onStart();
      ActionBar actionBar = getSupportActionBar();

      actionBar.setDisplayHomeAsUpEnabled(true);
      actionBar.setDisplayShowHomeEnabled(false);
      actionBar.setDisplayShowTitleEnabled(false);

      }

      ...

     @Override
     public boolean onCreateOptionsMenu(Menu menu) {
      MenuInflater inflater = getMenuInflater();
      inflater.inflate(R.menu.action_menu, menu);
      return true;
    }
}

With the above code, My application has an action bar. But the problem is that all the items defined in the above menu xml file are showing on the right hand side of the action bar, and the left side part of action bar is left blank.

You probably already noticed in my Activity code, I have:

actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);

The above two line codes are defined in my Activity onStart() callback which disable the action bar default text and icon.

But how can I have my custom items defined in menu xml file to be shown evenly on the action bar instead of only show on the right hand side of the action bar?

Jake Wharton
  • 75,598
  • 23
  • 223
  • 230
Leem.fin
  • 40,781
  • 83
  • 202
  • 354
  • To start you should use Sherlock classes : SerlockFragmentActivity ...etc maybe take a look here http://stackoverflow.com/questions/11264808/android-action-bar-with-two-stretched-buttons – An-droid Jul 08 '13 at 10:02

0 Answers0