3

I have tried setting the:

android:showAsAction=".."

to every one of these:

ifRoom, never, withText, always, collapseActionView

but I always got the same result, which is not having any buttons on the action bar, so I have to press the 'menu' button.

Here is a picture of the menu now :

current menu

<item android:id="@+id/smth1"
    android:title="@string/smth1"
    android:showAsAction="always"
    android:orderInCategory="1" />

I have even tried adding this:

android:uiOptions="splitActionBarWhenNarrow"

into application manifest file, but with no positive result (nothing changed).

I have tried running it on various kind of APIs (14, 16, 17, 19), but with the same result.

If my question seems to be unclear, here is a picture of a menu, which I would like to have:

enter image description here

Thanks for any help.

Community
  • 1
  • 1
Vilda
  • 1,675
  • 1
  • 20
  • 50
  • Do you use the v7 support library because there is many problems due to this library ? ... – Laurent Meyer Mar 23 '14 at 14:44
  • Yes, I use appcompat_v7 as a support library. – Vilda Mar 23 '14 at 14:46
  • 1
    Then search a bit in this way because there is a lot of "problems" with this library, here are a link which can be helpful : http://stackoverflow.com/a/17881737/2545832 (I think it'll solve your problem) – Laurent Meyer Mar 23 '14 at 14:49
  • 1
    possible duplicate of [android.support.v7 with \`ActionBarActivity\` no menu shows](http://stackoverflow.com/questions/17881547/android-support-v7-with-actionbaractivity-no-menu-shows) – Blo Mar 23 '14 at 14:56

2 Answers2

14

You need to use the compatibility namespace (see here)

<menu xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto">

<item android:id="@+id/menu_add_size"
    android:title="@string/menu_add_item"
    android:icon="@android:drawable/ic_menu_add" 
    app:showAsAction="always"/>
</menu>

Once you're using that you can use as many menu buttons as will fit. You're no longer limited to just two buttons + overflow showing.

Community
  • 1
  • 1
radley
  • 3,212
  • 1
  • 22
  • 18
0

You maybe just don't have enough space, you should first remove the title from your Activity by adding this to your onCreate method:

ActionBar actionBar = getActionBar();
actionBar.setDisplayShowTitleEnabled(false);

Then you can see here that the maximum number of icons you can display is directly linked to the width of your screen, on small phones you will only be able to see 2 icons in the ActionBar.

Yoann Hercouet
  • 17,894
  • 5
  • 58
  • 85