1. Are you ready for the Galaxy S20? Here is everything we know so far!

Call ShareActionProvider from a PopupMenu

Discussion in 'Android Development' started by hakiim, Dec 17, 2013.

  1. hakiim

    hakiim Lurker
    Thread Starter

    I'm trying to use the ShareActionProvider from a PopupMenu which is displayed after clicking an item of a listView. The problem is that the share menu doesn't display the icons as they should be.

    [​IMG]

    another problem appears when I click on the "see all" item, another share menu appears!

    [​IMG]
    Code (Text):
    1.  
    2.     public void openVideoMenu(View view) {
    3.         PopupMenu popup = new PopupMenu(this, view);
    4.         MenuInflater inflater = popup.getMenuInflater();
    5.         inflater.inflate(R.menu.video_menu, popup.getMenu());
    6.        
    7.         ShareActionProvider mShareActionProvider = (ShareActionProvider) popup.getMenu().findItem(R.id.share).getActionProvider();
    8.         Intent sendIntent = new Intent(Intent.ACTION_SEND);
    9.         sendIntent.setType("text/plain");
    10.         sendIntent.putExtra(Intent.EXTRA_TEXT, "http://www.youtube.com/watch?v="+ id);
    11.         mShareActionProvider.setShareIntent(sendIntent);
    12.         popup.show();
    13.     }
    14.  
    The XML configuration of the popupMenu looks like that:

    Code (Text):
    1.     <?xml version="1.0" encoding="utf-8"?>
    2.     <menu xmlns:android="http://schemas.android.com/apk/res/android" >
    3.         <item
    4.             android:id="@+id/share"
    5.             android:title="@string/share"
    6.             android:showAsAction="always"
    7.             android:icon="@drawable/ic_action_share"
    8.             android:actionProviderClass="android.widget.ShareActionProvider"/>
    9.     </menu>
    10.  
    thanks for your help
     



    1. Download the Forums for Android™ app!


      Download

       
Loading...

Share This Page

Loading...