0

Basically, I'm trying to add an item to the action bar, and it just doesn't work. I've looked up a bunch of topics but none of the tips really help. I'm running the app on Samsung Galaxy Note II.

Here's the relevant part of the activity:

public class AddItem extends Activity {


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu_add_item, menu);
    return super.onCreateOptionsMenu(menu);

}

Here's the menu xml file:

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

<item android:id="@+id/action_edit"
    android:icon="@drawable/ic_action_edit"
    android:title="Edit"
    app:showAsAction="always" />

Here's the Gradle build file piece:

android {
compileSdkVersion 21
buildToolsVersion "21.1.2"

defaultConfig {
    applicationId "***"
    minSdkVersion 16
    targetSdkVersion 21
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

And here's the styles xml:

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="@android:style/Theme.Holo.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="android:actionBarStyle">@style/MyActionBar</item>

</style>

<style name="MyActionBar"
    parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
    <item name="android:background">@drawable/abar</item>
</style>

That's basically it. Whatever I do, the "Edit" button goes into overflow(I have to press the menu button of the phone to get the popup). How do I get it to appear on my action bar?

Creepling
  • 5
  • 3

1 Answers1

0

It's because your phone has a hardware menu button, it would work as expected on any other device. Here you can find some info about how to cheat this.

Community
  • 1
  • 1