0
votes

In the main activity of this app I'm developing I want 4 menu items to be always displayed in the action bar.. I've used showAsAction = "always" for every item of the menu because my theme in this activity removes the title and only displays the icon, so I know there will be a big space in the action bar for icons to be displayed.. However, I'm not sure if setting all items to "always" is the correct way of doing it.. Is there other way or am I correct?

ps: showAsAction = "ifRoom" only allows my app to display 2 items in the action bar..

2
If you are interested in creating an ActionBar of your choice refer my answere here stackoverflow.com/questions/26439715/…codePG

2 Answers

1
votes

If you want to be sure that you will have all the 4 icons is better to create your own ActionBar like and do whatever you like.

In the original ActionBar you can use :

android:showAsAction="always"

It will force them to be there but take in consideration what is happening if it's still not enough room.

When contained within the action bar there is a finite maximum of action items based on the device's density-independent width. The action items can also not cover more than half the width of the action bar.

from here

0
votes

You could do this task programmatically:

@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    super.onCreateOptionsMenu(menu);

    getMenuInflater().inflate(R.menu.main, menu);

    for (int i = 0; i < menu.size(); i++) {
        menu.getItem(i).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    }

    return true;
}