Reputation: 1134
I'm sure this is a duplicate question - but I can't seem to find a fix online.
I'm trying to add a share button to my app. But at the moment I've got the issue where instead of the share icon (the weird USB/tree/node thing) - I've got the 3 dots associated with the overflow menu - that when pressed, open a popup option - which contains an item called share.
I have the correct functionality - but how can I use the icon, rather than the menu + popup nonsense.
Thank you -
Ollie
P.S. android:icon="@drawable/ic_action_share" is a completely valid path - so it's not that
QuestionActivity.java
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// Share Icon Functionality
case R.id.menu_item_share : Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Help me, I'm stuck on a game!");
sendIntent.putExtra(Intent.EXTRA_TEXT, shareTextFormatter());
sendIntent.setType("text/plain");
startActivity(sendIntent);
break;
}
return false;
}
menu_question.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="schemas.android.com/apk/res-auto"
tools:context="com.example.home.ditloids.QuestionActivity">
<item
android:id = "@+id/menu_item_share"
app:showAsAction = "ifRoom"
android:title = "Share"
android:icon="@drawable/ic_action_share"
android:actionProviderClass = "android.widget.ShareActionProvider" />
</menu>
Upvotes: 0
Views: 2720
Reputation: 8774
Your xmlns:app namespace is wrong, it's missing a "http://".
This leads to app:showAsAction being ignored.
Upvotes: 1
Reputation: 3274
In menu_question.xml , try changing showAsAction
to:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="schemas.android.com/apk/res-auto"
tools:context="com.example.home.ditloids.QuestionActivity">
<item
android:id = "@+id/menu_item_share"
app:showAsAction = "always"
android:title = "Share"
android:icon="@drawable/ic_action_share"
android:actionProviderClass = "android.widget.ShareActionProvider" />
Upvotes: 0