Actionbar not shown with AppCompat
Asked Answered
M

3

33

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?

Motte answered 29/8, 2013 at 11:57 Comment(0)
W
70

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>
Waterproof answered 29/8, 2013 at 11:59 Comment(0)
M
6

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

Mosesmosey answered 5/1, 2015 at 16:34 Comment(0)
P
0

I do debug with Doogee Valencia Y100Pro, and menu as "three little square" not visible, but when I extended my MainActivity with android.support.v7.app.ActionBarActivity, then I obtain text/icon menu in action bar. Next screenshot and menu.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/action_update"
        android:icon="@drawable/ic_refresh"
        android:title="@string/action_update"
        app:showAsAction="always"/>
    <item android:id="@+id/action_settings"
        android:title="@string/action_settings"
        app:showAsAction="ifRoom"/>
</menu>
Pathogen answered 22/11, 2015 at 20:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.