my solution is based on v7 support library, toolBar, ActionBarActivity, Android Studio
1- uninstall app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
2- make sure your base theme is Theme.AppCompat.Light.NoActionBar
3- go to the source code ShareActionProvider by typing "ShareActionProvider" anywhere in your code, then import v7, then hover over it (ctrl + left click)
4- copy the code into it and paste it into a new java file in the project directory
5 go to your own ShareActionProvider file and delete this import if you have import android.support.v7.appcompat.R
6- specify your own icon, because by default black Drawable myDrawable = mContext.getResources().getDrawable(R.drawable.ic_share); activityChooserView.setExpandActivityOverflowButtonDrawable(myDrawable); Drawable myDrawable = mContext.getResources().getDrawable(R.drawable.ic_share); activityChooserView.setExpandActivityOverflowButtonDrawable(myDrawable);
7- go to your business and delete the import you made in step 3 (to use your own file)
8- go to your onCreateOptionsMenu, it should be something like this:
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_main, menu); MenuItem item = menu.findItem(R.id.menu_item_share); mShareActionProvider = new ShareActionProvider(MainActivity.this); MenuItemCompat.setActionProvider(item , mShareActionProvider); Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.putExtra(Intent.EXTRA_TEXT, "Hello World"); shareIntent.setType("text/plain"); mShareActionProvider.setShareIntent(shareIntent); return true; }
9- last step - do not forget to change your menu.xml
app:actionProviderClass= "com.yourPackageName.ShareActionProvider" />
source share