How to hide the share action (which use most) icon near the share action provider?
If you wish to keep all the share history data model, but just don't want the extra "default share activity" icom. The answer at How do you turn off share history when using ShareActionProvider? is not good enough.
What you should do is:
- Copy these classes from the ActionBarSherlock to your project code
- ShareActionProvider.java
- ActivityChooserView.java
- At your ShareActionProvider.java class, import the ActivityChooserView.java which you just copied instead of the ActionBarShelock file location
- At the ActivityChooserView.java -
- find the line
if (activityCount > 0 && historySize > 0)
- replace this line with
if (false)
(it's pretty ugly, but it's the quickest fix. you can delve into the code to remove all occurrences of DefaultActivity implementation)
- find the line
Edit:
Don't forget to set the new ActionProvider
to your menu item, from XML it would look like: android:actionProviderClass="com.*.CustomShareActionProvider"
That's it!
How do you turn off share history when using ShareActionProvider?
There is no API to do this. However, the class is really simple and you could very easily create your own version of ShareActionProvider
that did not keep a history. You would just have to determine the sort order of the possible targets using some other means of ordering (e.g., alphabetically).
Remove extra icon at actionbar (when using ShareActionProvider and ActionBarSherlock)
I don't know if you resolved your problem but I had the same issue to remove history of ShareActionProvider
. I tried everything and the near answer I found was the same as you (How to hide the share action icon?).
After some researches, I found this trick on the second comment:
Action Bar Sherlock has depreciated methods
- Copy/Paste the 3 classes (
ShareActionProvider
,ActivityChooserView
andActivityChooverModel
) from ABS to your package. - Replace the import by yours with your own package.
- Change the line
if (activityCount > 0 && historySize > 0)
byif (false)
in your newActivityChooserView
.
(You will get an error: "setActived" is not available for your current version) - Save it and close the class.
- Replace the class in your menu.xml your item by
android:actionProviderClass="com.myapp.ShareActionProvider"
- In your
Manifest
, make theminSdkVersion
equals to 11. Save your project. Clean it. - Return to your
Manifest
, replace yourminSdkVersion
by the old one you used. Save and clean.
It works perfectly. Let me know if this tip resolved your problem.
How to hide last sharing icon?
Don't use the ShareActionProvider when creating your ActionBar, instead, just use a standard MenuItem (and set the icon to share). Then you will not see the last share option.
How to fix the share icon in the support actionbar
As mentioned here when using support library this can be fixed really easily. This method won't turn off the share history but will hide the icons from actionbar.
I just needed to subclass the Android.Support.V7.Widget.ShareActionProvider
like the following: (C# using Xamarin)
public class MyShareActionProvider : Android.Support.V7.Widget.ShareActionProvider
{
public SingleArticleShareActionProvider (Context context) : base (context)
{}
public override View OnCreateActionView ()
{
return null;
}
}
and then inside OnCreateOptionsMenu
use the MyShareActionProvider
like:
var share_article = menu.FindItem (Resource.Id.action_share);
var share = new SingleArticleShareActionProvider (globalContext);
Android.Support.V4.View.MenuItemCompat.SetActionProvider (share_article, share);
share_article.SetIcon (Resource.Drawable.abc_ic_menu_share_mtrl_alpha);
share.SetShareIntent (CreateIntent ());
You can use any icon you like with the method SetIcon
.
ShareActionProvider Shows two Icons A System Icon And A share Icon
That's exactly what a ShareActionProvider
is supposed to look like. If you just want a share button, then stop using ShareActionProvider
. I.e., update your XML to remove the ShareActionProvider
:
<item
android:id="@+id/share"
android:title="Share"
android:icon="@drawable/share"
app:showAsAction="ifRoom"
/>
(You'll need to add your own @drawable/share
to your app such as one from the material design icons).
Then override your onOptionsItemSelected() method to start your share when the menu item is tapped:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getMenuId()) {
case R.id.share:
Intent shareIntent = createShareIntent();
startActivity(shareIntent);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
You don't need to do anything in onCreateOptionsMenu
except inflating your menu.
Remove most recent share app
If you don't want to show recent share app then remove ShareActionprovider.
and add a icon to menu and handle share action like this
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
String shareBody = "Here is the share content body";
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject Here");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
startActivity(Intent.createChooser(sharingIntent, "Share via"));
Setting a custom share icon on Actionbar ShareActionProvider without ActionBarSherlock
You can subclass ShareActionProvider, overriding only the constructor and createActionView().
From here, you can get the View from super, casting it to ActivityChooserView so you can call
setExpandActivityOverflowButtonDrawable(Drawable) to change the icon.
package com.yourpackagename.whatever;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.v7.internal.widget.ActivityChooserView;
import android.support.v7.widget.ShareActionProvider;
import android.view.View;
import com.yourpackagename.R;
public class CustomShareActionProvider extends ShareActionProvider {
private final Context mContext;
public CustomShareActionProvider(Context context) {
super(context);
mContext = context;
}
@Override
public View onCreateActionView() {
ActivityChooserView chooserView =
(ActivityChooserView) super.onCreateActionView();
// Set your drawable here
Drawable icon =
mContext.getResources().getDrawable(R.drawable.ic_action_share);
chooserView.setExpandActivityOverflowButtonDrawable(icon);
return chooserView;
}
}
Related Topics
Android: Custom Separator (Or Even Item) in Listview Depening on Content of Item
How to Use Selector to Tint Imageview
Triggering Event When Button Is Pressed Down in Android
Setting Android Theme Background Color
How to Show/Hide Password in Textformfield
How to Download a File from a Server and Save It in Specific Folder in Sd Card in Android
Opencv Image Comparison in Android
Android Emulator Screen Fills Up Only Some Fraction Part of Actual Android Emulator Screen
Asynctask, Must It Take Such a Performance Penalty Hit...
Page Scroll When Soft Keyboard Popped Up
Android Device Is Not Connected to Usb for Debugging (Android Studio)
Android 4.4 Giving Err_Cache_Miss Error in Onreceivederror for Webview Back
How to Load HTML String in a Webview
Tablayout Tab Title Text in Lower Case
Android Sharedpreferences , How to Save a Simple Int Variable