Search code examples
androidandroid-studioandroid-actionbar

ActionBar menu Changed it's behavior after I changed inheritance from Activity to AppCompatActivity


I took an older project of mine and imported it into Android Studio. As part of it, I had to change inheritance from Activity to AppCompetActivity to support ActionBar with its new API.

Now I have an unexpected behavior as a result: All menu items are flattened instead of being hidden behind the three dots menu icon like so:

Inheriting from Activity:

enter image description here

Inheriting from AppCompatActivity:

enter image description here

Any Idea?

Edited:

Here is my menu.xml:

enter image description here


Solution

  • Need to update namespace android:showAsAction to app:showAsAction attribute. Use the following code:

    <?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:orderInCategory="100"
            android:title="Menu Item 1"
            app:showAsAction="never" />
    
        <item
            android:orderInCategory="100"
            android:title="Menu Item 2"
            app:showAsAction="never" />
    </menu>
    

    enter image description here