ShareActionProvider is null

前端 未结 2 1093
萌比男神i
萌比男神i 2021-02-06 20:15

I have been searching for 3 or 4 days about a solution on this. I have tried: Null Pointer exception in using support library share action provider or why MenuItemCompat.getAct

相关标签:
2条回答
  • 2021-02-06 20:22

    You have wrong namespace usage in XML:

    <menu xmlns:android="http://schemas.android.com/apk/res/android"             xmlns:app="http://schemas.android.com/apk/res-auto">

      <item android:actionProviderClass="android.support.v7.widget.ShareActionProvider"

    should be app:actionProviderClass (the provider class is from apk resources, not native android classes).

    See https://stackoverflow.com/a/32602896/907576

    0 讨论(0)
  • 2021-02-06 20:39

    You could just create a ShareActionProvider and assign it.

    mShareActionProvider = new ShareActionProvider();
    mShareActionProvider.setShareIntent(createShareIntent())
    MenuItemCompat.setActionProvider(item, mShareActionProvider);
    
    0 讨论(0)
提交回复
热议问题