Search code examples
androidandroid-actionbar-compat

Menu items doesn't show up on the actionbar using Android Studio 1.4


The previous stackoverflow questions on this exact title are "old".

Android Studio 1.4

API Level 16

com.android.support:appcompat-v7:23.0.1

I've created an empty activity and added the following menu.

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

<item android:id="@+id/action_search"
    android:icon="@drawable/icon"
    app:showAsAction="always"
    android:title="Search" />

<item android:id="@+id/action_compose"
    android:icon="@drawable/icon"
    app:showAsAction="ifRoom"
    android:title="Compose" />

<item android:id="@+id/action_compose1"
    android:icon="@drawable/icon"
    app:showAsAction="ifRoom"
    android:title="Compose" />

<item android:id="@+id/action_compose2"
    android:icon="@drawable/icon"
    app:showAsAction="ifRoom"
    android:title="Compose" />

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    Toast.makeText(this, "onCreateOptionsMenu", Toast.LENGTH_LONG).show();
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main_activity_actions, menu);
    return super.onCreateOptionsMenu(menu);
}

In the Android Studio designer, I see the two icons and a ... menu icon.

In Android Studio Designer

But when I launch the app in the emulator, all I see is the two icons and no overflow ... menu icon.

enter image description here

When I hit the Menu button, then I see the additional entries though.

https://github.com/danvallejo/actionbar

Any ideas?


Solution

  • The solution was to use the support library Toolbar and to modify the AndroidManifest to change the them to @style/Theme.AppCompat.NoActionBar

    <android.support.v7.widget.Toolbar
       android:id="@+id/my_toolbar"
       android:layout_width="match_parent"
       android:layout_height="?attr/actionBarSize"
       android:background="?attr/colorPrimary"
       android:elevation="4dp"
       android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
       app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>