Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Actionbar not shown with AppCompat

I am backporting my app to API7 with AppCompat and have a problem with the actionbar.

When I use FragmentActivity the actionbar is shown on my phone (API18), but with ActionBarActivity it shows up as the optionmenu by pressing the menubutton.

On the emulator with API7 the actionbar is always shown as an optionsmenu.

Any ideas?

like image 923
electrofant Avatar asked Aug 29 '13 11:08

electrofant


2 Answers

Use the compat name space for your menu items like this:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:compat="http://schemas.android.com/apk/res-auto" >
    <item android:id="@+id/action_whatever"
      android:icon="@drawable/ic_action_whatever"
      android:title="@string/whatever"
      compat:showAsAction="ifRoom"  />
</menu>
like image 98
flx Avatar answered Nov 15 '22 19:11

flx


Related to a duplicate that points to this post, I was having trouble making my buttons appear as action items instead of overflow items, despite having showAsAction set to always. I managed to coerce it by extending my activity with Activity instead of ActionBarActivity. According to this answer, this is acceptable if you don't need to support api levels below 11.

...extends ActionBarActivity:

extends ActionBarActivity

...extends Activity:

enter image description here

like image 35
adamdport Avatar answered Nov 15 '22 19:11

adamdport