I can only find solutions to this for the case of using the support library. Facts:
build.gradle:
dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:design:22.2.0' }
menu_main.xml:
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity"> <item android:id="@+id/ab_main_share" android:showAsAction="ifRoom|withText" android:title="Share" android:icon="@drawable/ic_settings_input_antenna_black_24dp" android:actionProviderClass= "android.widget.ShareActionProvider" /> <item android:id="@+id/ab_main_delete" android:showAsAction="ifRoom|withText" android:title="Delete" android:icon="@drawable/ic_delete_black_24dp" /> <item android:id="@+id/action_settings" android:title="@string/action_settings" android:orderInCategory="100" app:showAsAction="never" /> </menu>
MainActivity.java:
public class MainActivity extends Activity { private ShareActionProvider mShareActionProvider; ... @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate menu resource file. MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.menu_main, menu); /** Getting the actionprovider associated with the menu item whose id is share */ mShareActionProvider = (ShareActionProvider) menu.findItem(R.id.ab_main_share).getActionProvider(); /** Setting a share intent */ mShareActionProvider.setShareIntent(getDefaultShareIntent()); return super.onCreateOptionsMenu(menu); }
And the result is that the actions appear in the overflow. I tried also to put just one action, but I get the same result. So it's not a problem of not having room in the action bar (and the name of the app or the application icon is not so wide).
Am I missing something? I did these thing before with the support library and had no problems, but this app is minSdkVersion 17, so there's no reason to use it anymore.