I was working around my old ShareAction
on my ActionBar
and it was working since I updated my Packages on SDK Manager
. I saw this doc from Google which says,
To add a "share" action to your activity, put a
ShareActionProvider
in the app bar's menu resource. For example:
And I've added the same without adding any Icons
:
<item android:id="@+id/action_share"
android:title="@string/share"
app:showAsAction="ifRoom"
app:actionProviderClass="android.support.v7.widget.ShareActionProvider"/>
I was using:
app:actionProviderClass="Mypackagename.ShareActionProvider"
With a custom ShareActionProvider
with the following code.you can see it here.
I saw a hack or a trick to do that (with ShareActionProvider
-v4) and everything was good since I decided to use android.support.v7.widget.ShareActionProvider
.
So, Here is my currently code:
<item
android:id="@+id/shareac"
android:title="@string/share"
app:actionProviderClass="android.support.v7.widget.ShareActionProvider"
app:showAsAction="always" />
I didn't use the Icon
because here the doc says,
You do not need to specify an icon, since the
ShareActionProvider
widget takes care of its own appearance and behavior. However, you do need to specify a title with android:title, in case the action ends up in the overflow menu.
And here is what I've done so far:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main_details, menu);
// Locate MenuItem with ShareActionProvider
MenuItem item = menu.findItem(R.id.shareac);
// Fetch and store ShareActionProvider
mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(item);
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
Bundle extra = getIntent().getExtras();
String title = extra.getString("title");
Bundle extraurl = getIntent().getExtras();
String url = extraurl.getString("url");
shareIntent.putExtra(Intent.EXTRA_TEXT, "Check this new project from something : " + title + url);
shareIntent.setType("text/plain");
mShareActionProvider.setShareIntent(shareIntent);
return true;
}
So, here what I see right now in Android Studio 1.5.1 Is,
And if run and compile the app:
As you can see, the size of ShareAction
is too much. (It's violating the MaterialDesign
guideline I guess).
I forgot to say, I've already tried android:icon="@mipmap/ic_share"
which that was working with my previous method/trick. But, check this Preview from AndroidStudio
:
And here is after compiled:
Nothing changed!
So, my question: is that a bug or what am I doing wrong here?
Intent.createChooser
didn't work also: from: https://mcmap.net/q/862601/-appcompat-shareactionprovider-icon-is-too-big-compared-to-other-icons
Edit:
The most interesting part, i just saw the same design and the same resutls from Google on the following course and on that app which they've called it SunShine app:
Course:
https://www.udacity.com//course/viewer#!/c-ud855/l-3961788738/m-4294896397
a title with android:title, in case the action ends up in the overflow menu
. why the icon size is too much? what about other screens? also that doesn't work btw. – Opacity