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>
請幫助。