Size of ShareAction icon issue on ActionBar with ShareActionProvider-v7
Asked Answered
P

4

11

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,

enter image description here

And if run and compile the app:

enter image description here

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:

enter image description here

And here is after compiled:

enter image description here

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:

Applink

Course:

https://www.udacity.com//course/viewer#!/c-ud855/l-3961788738/m-4294896397

Pronucleus answered 25/1, 2016 at 14:43 Comment(7)
Have you tried just using an icon? If that fixes the size, it will be more efficient at run time than actually re sizing the current icon.Matsuyama
I just updated the question.i forgot to say that.But, docs is wrong? look at the You do not need to specify an iconOpacity
You don't need to but if you are trying to achieve the size of the icon your best best bet is to try an icon and see if that fixes the issue. It may be using Holo icons rater than the Design Icons. Try adding an icon and see if it works.Matsuyama
The thing is, i did that, and it was working before! see the updated question please.Opacity
Gotcha. Also you should not put the icons inside of mipmap. They should be in the drawables folder. mipmap formats icons differently. Try putting the share inside of the drawables. and see if that works. Mipmap is for app icon only. Also make sure you are using 4 different versions of the icon. in the drawables folderMatsuyama
Thank you, i knew that already, but that's not the point, i mean if docs 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. why the icon size is too much? what about other screens? also that doesn't work btw.Opacity
Let us continue this discussion in chat.Matsuyama
P
4

Okay, As ianhanniballake at this post said,

Icons in material design are 24dp x 24dp, as properly reflected by the SearchView. However, ShareActionProvider has not yet been updated to material design by default.

By the way, i've just posted a question/report to code.google.com which you can see it here:

http://code.google.com/p/android/issues/detail?id=200335

It seems that default icon is 24dp x 24dp but it should be like this:

enter image description here

But now, it is like this:

enter image description here

Seems to be a bug and still waiting for accepting or answering about it.I'll update this post if they answered.7 days passed!

UPDATE:

Finally, they've assigned the defect on to the development team and they will update this issue with more information as it becomes available.

Big thanks to [email protected] at Google for support.

The answer is available here: http://code.google.com/p/android/issues/detail?id=200335#c10

I will update this answer if any updates or any fixes was available.

UPDATE: http://code.google.com/p/android/issues/detail?id=200335#c12

Hi, The development team has fixed the issue that you have reported and it will be available in a future build. Thanks

Pronucleus answered 9/2, 2016 at 14:55 Comment(1)
This issue still persist in com.android.support:appcompat-v7:25.0.0. Seems android reverted the fix and its back to being a large icon.Held
B
2

Icons in material design are 24dp x 24dp, as properly reflected by the SearchView. However, ShareActionProvider has not yet been updated to material design by default.

You can set actionModeShareDrawable in your theme to set the share icon in the ShareActionProvider:

<item name="actionModeShareDrawable">@drawable/share_icon</item>

Note that ShareActionProvider is not found anywhere in the material design guidelines and with Android M's Direct Share capability (which requires you use a standard share intent at this time), it is unclear on whether the ShareActionProvider is a suggested pattern any more.

For more detail Visit Here.

AppCompat ShareActionProvider icon is too big compared to other icons

Blase answered 3/2, 2016 at 7:12 Comment(1)
As you can see, actionModeShareDrawable didn't work, btw, seems like that link had the same issue.Opacity
M
1

Change the icon Pragmatically

@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);
    //Here
    item.setIcon(getResources().getDrawable(R.drawable.ic_share));
    return true;
}

or Theme

<item name="actionModeShareDrawable">@drawable/ic_share</item>
Matsuyama answered 25/1, 2016 at 16:10 Comment(1)
Thank you, but seems like doc is wrong or it's a bug. that didn't work.Opacity
E
0

If you don't need custom icon for share menu item then try android resource for share menuitem as below:

 <item android:id="@+id/action_share"
   android:title="@string/share"
   app:showAsAction="ifRoom"
   android:icon="@android:drawable/ic_share"
   app:actionProviderClass="android.support.v7.widget.ShareActionProvider"/>

See here

Erne answered 7/2, 2016 at 12:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.