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.
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>
The only way I found was to create my own layout for activity chooser view. I went to ActivityChooserView.java and found next lines:
Then I followed to abc_activity_chooser_view.xml and saw:
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:
P.S. Be advised that filenames and layouts may vary depending on app compat lib version, but the algorithm is the same.
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 theShareActionProvider
: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 theShareActionProvider
is a suggested pattern any more.The solution I ended up using is not use
ShareContentProvider
anymore, instead i'm usingIntent.createChooser()
. It was pretty simple to do these changes and it opens the new share dialog, as shown below:share icon in action bar:
Dialog:
menu.xml
Fragment class: