why MenuItemCompat.getActionProvider returns null?

前端 未结 12 1030
天命终不由人
天命终不由人 2020-11-29 06:33

I tried to use android.support.v7.widget.ShareActionProvider on actionbar in my app. So I followed the example from android document but got some issues.
Here\'s my m

12条回答
  •  有刺的猬
    2020-11-29 07:03

    There is another potential related problem. If your MenuItem is always present in the ActionBar, using the following code:

    menuItem?.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS) 
    

    the resulting Menu item won't work (it will be visible, but not enabled). There are two options, either change the ShowAsAction type or call setShareIntent directly in the onCreateOptionsMenu() function:

    this@MyAwesomeActivity.runOnUiThread(java.lang.Runnable {
         actionProvider.setShareIntent(shareIntent)
    })
    

提交回复
热议问题