Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AppCompat ShareActionProvider icon is too big compared to other icons

I changed the ActionBarSherlock to AppCompat v7. I already did all the changes that are needed to make it work, but something weird is happening with share icon (which is using ShareActionProvider). The share icon is too big compared to other icons. I also use the support library for my search, and its size is correct. The problem is just with the share icon.

enter image description here

my_menu.xml:

    <menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:moblee="http://schemas.android.com/apk/res-auto" >
    <item
        android:id="@+id/menu_share"
        android:padding="10dp"
        android:title="@string/menu_share"
        moblee:actionProviderClass="android.support.v7.widget.ShareActionProvider"
        moblee:showAsAction="always"/>
    <item
        android:id="@+id/menu_search"
        android:title="@string/menu_search"
        moblee:actionViewClass="android.support.v7.widget.SearchView"
        moblee:showAsAction="always"/>
</menu>

fragment:

public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.my_menu, menu);
    MenuItem item = menu.findItem(R.id.menu_share);
    ShareActionProvider shareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(item);
    shareActionProvider.setShareIntent(getDefaultShareIntent());
}

styles.xml

<style name="Theme.Custom" parent="Theme.AppCompat.Light.DarkActionBar">

        <item name="colorPrimary">@color/main_bar</item>
        <item name="colorPrimaryDark">@color/main_bar</item>
        <item name="actionBarItemBackground">@drawable/selectable_background_custom</item>
        <item name="selectableItemBackground">@drawable/selectable_background_custom</item>

        <item name="android:windowBackground">@color/background</item>

        <item name="android:popupMenuStyle">@style/PopupMenu.Custom</item>
        <item name="android:dropDownListViewStyle">@style/DropDownListView.Custom</item>
        <item name="android:actionDropDownStyle">@style/DropDownNav.Custom</item>
        <item name="android:actionModeBackground">@drawable/cab_background_top_custom</item>
        <item name="android:actionModeSplitBackground">@drawable/cab_background_bottom_custom</item>
        <item name="android:actionModeCloseButtonStyle">@style/ActionButton.CloseMode.Custom</item>

        <item name="vpiTabPageIndicatorStyle">@style/VpiTabPageIndicator.Custom</item>
        <item name="android:editTextBackground">@drawable/edit_text_holo_light</item>
        <item name="android:listChoiceBackgroundIndicator">@drawable/list_selector_holo_light</item>
        <item name="android:activatedBackgroundIndicator">@drawable/activated_background_holo_light</item>
        <item name="android:fastScrollThumbDrawable">@drawable/fastscroll_thumb_holo</item>
        <item name="android:listViewStyle">@style/ListViewCustom</item>
        <item name="android:gridViewStyle">@style/GridViewCustom</item>
        <item name="android:textViewStyle">@style/TextViewCustom</item>
        <item name="android:checkboxStyle">@style/CheckBoxCustom</item>
    </style>

    <style name="PopupMenu.Custom" parent="@style/Widget.AppCompat.ListPopupWindow">
        <item name="android:popupBackground">@drawable/menu_dropdown_panel_custom</item>
    </style>

    <style name="DropDownListView.Custom" parent="@style/Widget.AppCompat.ListView.DropDown">
        <item name="android:listSelector">@drawable/selectable_background_custom</item>
    </style>

    <style name="Theme.Custom.Widget" parent="@style/Theme.AppCompat">
        <item name="android:popupMenuStyle">@style/PopupMenu.Custom</item>
        <item name="android:dropDownListViewStyle">@style/DropDownListView.Custom</item>
    </style>
like image 911
heloisasim Avatar asked Jun 17 '15 19:06

heloisasim


2 Answers

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.

like image 89
ianhanniballake Avatar answered Oct 14 '22 11:10

ianhanniballake


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)));
}
like image 33
heloisasim Avatar answered Oct 14 '22 11:10

heloisasim