i'm trying to solve the "item does not implement SupportMenuItem: returning null" using the support library, but i can't figure out how to do... I've also set the proguard as indicated in the following question (i hope in correct way) why MenuItemCompat.getActionProvider returns null? (see yshahak answer) but still give me the error.
Activity content (in the manifest i use the Theme.AppCompat as theme):
import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.ShareActionProvider;
public class MyActivity extends AppCompatActivity {
private ShareActionProvider mShareActionProvider;
public String default_share_text;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
MenuItem menuItem = menu.findItem(R.id.menu_item_share);
mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(menuItem);
mShareActionProvider.setShareIntent(DoShare(default_share_text));
return true;
}
// Call to update the share intent
public void changeShareIntent(Intent shareIntent) {
if (mShareActionProvider != null) {
mShareActionProvider.setShareIntent(shareIntent);
}
}
// Share Intent
public Intent DoShare(String myText){
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, myText);
sendIntent.setType("text/plain");
return sendIntent;
}
}
activity_menu.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/menu_item_share"
app:showAsAction="always"
android:title="@string/share"
app:actionProviderClass="android.support.v7.widget.ShareActionProvider" />
</menu>
Proguard
I've followed this tutorial http://developer.android.com/tools/help/proguard.html
Build.Grandle (Module App)
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro', 'proguard-rules-new.pro'
}
}
proguard.cfg (in the root app directory)
-keep class android.support.v7.widget.ShareActionProvider { *; }
project.properties (created in the root app directory, also tried in local.properties)
proguard.config=proguard.cfg
I don't know if i've set properly proguard, but i still get the same SupportMenuItem error