AppCompat ShareActionProvider icon is too big compared to other icons

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.


The solution I ended up using is not use ShareContentProvider anymore, instead i'm using Intent.createChooser(). It was pretty simple to do these changes and it opens the new share dialog, as shown below:

share icon in action bar:

enter image description here

Dialog:

enter image description here

menu.xml

<item
    android:id="@+id/menu_share"
    android:checkable="true"
    android:icon="@drawable/ic_menu_share"
    myapp:showAsAction="always"
    android:title="@string/menu_share"/>

Fragment class:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int itemId = item.getItemId();
    if (itemId == R.id.menu_share) {
        showShareDialog();
    }
        return super.onOptionsItemSelected(item);
}

private void showShareDialog(String message) {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND);
    intent.setType("text/plain");

    intent.putExtra(Intent.EXTRA_SUBJECT, mTitle);
    intent.putExtra(Intent.EXTRA_TEXT, mMessage);

    startActivity(Intent.createChooser(intent, getString(R.string.menu_share)));
}

The only way I found was to create my own layout for activity chooser view. I went to ActivityChooserView.java and found next lines:

    LayoutInflater inflater = LayoutInflater.from(getContext());
    inflater.inflate(R.layout.abc_activity_chooser_view, this, true);

Then I followed to abc_activity_chooser_view.xml and saw:

<view xmlns:android="http://schemas.android.com/apk/res/android"
class="android.support.v7.internal.widget.ActivityChooserView$InnerLayout"
android:id="@+id/activity_chooser_view_content"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
style="?attr/activityChooserViewStyle">

<FrameLayout
    android:id="@+id/expand_activities_button"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:focusable="true"
    android:addStatesFromChildren="true"
    android:background="?attr/actionBarItemBackground">

    <ImageView android:id="@+id/image"
        android:layout_width="32dip"
        android:layout_height="32dip"
        android:layout_gravity="center"
        android:layout_marginTop="2dip"
        android:layout_marginBottom="2dip"
        android:layout_marginLeft="12dip"
        android:layout_marginRight="12dip"
        android:scaleType="fitCenter"
        android:adjustViewBounds="true" />

</FrameLayout>

<FrameLayout
    android:id="@+id/default_activity_button"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:focusable="true"
    android:addStatesFromChildren="true"
    android:background="?attr/actionBarItemBackground">

    <ImageView android:id="@+id/image"
        android:layout_width="32dip"
        android:layout_height="32dip"
        android:layout_gravity="center"
        android:layout_marginTop="2dip"
        android:layout_marginBottom="2dip"
        android:layout_marginLeft="12dip"
        android:layout_marginRight="12dip"
        android:scaleType="fitCenter"
        android:adjustViewBounds="true" />

</FrameLayout>

As you can see the sizes for image views are 32dp, when normally it should be 24dp.

EDIT:

The solution is simple - you create your own layout with the exact same name and put it into your resources folder. The only ammendment you gotta do to make things right is to change size of both image views like this:

                <ImageView android:id="@+id/image"
                   android:layout_width="24dip"
                   android:layout_height="24dip"
                   android:layout_gravity="center"
                   android:layout_margin="12dip"
                   android:scaleType="fitCenter"
                   android:adjustViewBounds="true"
                   tools:ignore="DuplicateIds"/>

P.S. Be advised that filenames and layouts may vary depending on app compat lib version, but the algorithm is the same.