I am trying to use ShareActionProvider in my Android App. First I tried to use default ShareActionProvider
. But unfortunately I found android not provides any method to change the color of share icon.
So I use ActionBarSherlock
. I was able to change the background , but I am not able to remove the spaces around menu item and shareaction provider.
Secondly the right history icon.
Please help.
Here is the source code.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(R.style.MyApp);
setContentView(R.layout.activity_fullscreen);
ActionBar actionBar = getSupportActionBar();
actionBar.setHomeButtonEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
LayoutInflater inflator = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View custom = inflator.inflate(R.layout.actionbar_view, null);
actionBar.setCustomView(custom);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_CUSTOM);
actionBar.setDisplayShowCustomEnabled(true);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getSupportMenuInflater().inflate(R.menu.menu, menu);
MenuItem actionItem = menu.findItem(R.id.share_action_provider);
ShareActionProvider actionProvider = (ShareActionProvider) actionItem.getActionProvider();
actionProvider.setShareHistoryFileName(null);
actionProvider.setShareIntent(createShareIntent());
return true;
}
My style
<style name="MyApp" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="windowActionBarOverlay">true</item> <!-- for ActionBarSherlock -->
</style>
My Menu XML
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/contest"
android:showAsAction="always"
android:icon="@drawable/contest" />
<item android:id="@+id/share_action_provider"
android:showAsAction="always"
android:actionProviderClass="com.actionbarsherlock.widget.ShareActionProvider" />
</menu>
My Custom View
<RelativeLayout
android:id="@+id/actionLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/homeIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/home_button_background"
android:layout_alignParentLeft="true"
android:onClick="onHomeClick">
</ImageView>
</RelativeLayout>
Here is the screenshot.