0
import android.widget.ShareActionProvider; 
... 
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { 
    inflater.inflate(R.menu.detailfragment, menu); 
    MenuItem menuItem = menu.findItem(R.id.action_share); 
    ShareActionProvider mShareActionProvider = (ShareActionProvider)MenuItemCompat.getActionProvider(menuItem); 

    if (mShareActionProvider != null) { 
     mShareActionProvider.setShareIntent(createShareForecastIntent()); 
    } else { 
     Log.d(LOG_TAG, "Share Action Provider is null?"); 
    } 
} 

這段代碼顯示了以下錯誤:ActionProvider不能轉換到ShareActionProvider

incompatible types: ActionProvider cannot be converted to ShareActionProvider 

以下是detailfragment.xml文件:

<?xml version="1.0" encoding="utf-8"?> 
<menu xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto"> 

    <item android:id="@+id/action_share" 
     android:title="@string/action_share" 
     app:showAsAction="always" 
     app:actionProviderClass="android.support.v7.widget.ShareActionProvider" /> 
</menu> 

請幫助。

回答

0

android.widget.ShareActionProviderandroid.support.v7.widget.ShareActionProvider不是同一類。更改您的進口以匹配您的actionProviderClass

-1

它爲我工作,試試看。 import android.support.v7.widget.ShareActionProvider 將其刪除,並添加此導入: import android.widget.ShareActionProvider;

code

相關問題