Unable to cast Action Provider to Share Action Provider

后端 未结 8 1070
一个人的身影
一个人的身影 2020-11-29 19:58

Below is the code for my Activity

    import android.app.Activity;
    import android.os.Bundle;
    import android.support.v7.widget.ShareActionProvider;
          


        
8条回答
  •  天命终不由人
    2020-11-29 20:37

    I had the same problem and I have found the solution:

    1) You have to use:

    
    
        
    
    

    2) and in Java

    import android.support.v7.widget.ShareActionProvider;
    

    and

    // Locate MenuItem with ShareActionProvider
    MenuItem item = menu.findItem(R.id.menu_share);
    // Fetch and store ShareActionProvider
    mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(item);
    

提交回复
热议问题