0

I'm trying to implement the share functionality within my app. So far it works fine and I can share text to all other apps. The problem is the way it's shown.

I want something like just the share icon visible and then when user taps on it, it opens the OS dialog and lets user choose the app they want to share content to.

    var share_article = menu.FindItem (Resource.Id.action_share);
    var share_article_provider = (Android.Support.V7.Widget.ShareActionProvider) Android.Support.V4.View.MenuItemCompat.GetActionProvider (share_article);
    share_article_provider.SetShareIntent (CreateIntent ());

and the xml:

<item 
    android:id="@+id/action_share"
    myapp:showAsAction="ifRoom"
    android:title="share"
    myapp:actionProviderClass="android.support.v7.widget.ShareActionProvider" />

My app currently looks like this:

enter image description here

There's also a white border around it that I don't like. Is there any way to change the icon??

How do I fix it??

Vahid Amiri
  • 10,769
  • 13
  • 68
  • 113

2 Answers2

1

You just want to turn off your share history.There is no official API to do this, but you can make your own ShareActionProvider. Actually there are two similar question on SO:

  1. How do you turn off share history when using ShareActionProvider?
  2. How to hide the share action (which use most) icon near the share action provider?

Wish these could help you.

Community
  • 1
  • 1
penkzhou
  • 1,200
  • 13
  • 30
-1

As mentioned here when using support library this can be fixed really easily. This method won't turn off the share history but will hide the icons from actionbar. I just needed to subclass the Android.Support.V7.Widget.ShareActionProvider like the following: (C# using Xamarin)

public class MyShareActionProvider : Android.Support.V7.Widget.ShareActionProvider
{
    public SingleArticleShareActionProvider (Context context) : base (context)
    {}

    public override View OnCreateActionView ()
    {
        return null;
    }
}

and then inside OnCreateOptionsMenu use the MyShareActionProvider like:

var share_article = menu.FindItem (Resource.Id.action_share);
var share = new SingleArticleShareActionProvider (globalContext);

Android.Support.V4.View.MenuItemCompat.SetActionProvider (share_article, share);
share_article.SetIcon (Resource.Drawable.abc_ic_menu_share_mtrl_alpha);
share.SetShareIntent (CreateIntent ());

You can use any icon you like with the method SetIcon.

Community
  • 1
  • 1
Vahid Amiri
  • 10,769
  • 13
  • 68
  • 113