且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

设置在动作条ShareActionProvider一个自定义的共享图标

更新时间:2023-01-27 11:03:48

在我期待自定义操作栏,平时我看的第一个地方是ActionBarSherlock主题和风格。

我发现福尔摩斯主题使用actionModeShareDrawable在theme.xml文件。

试着改变你的主题直接包含actionModeShareDrawable项目。

 <样式名称=Theme.MyApp父=Theme.Sherlock.Light>
    <项目名称=actionModeShareDrawable> @可绘制/ ic_action_share< /项目>
< /风格>
 

I'm trying to set the icon ShareActionProvider, need a solid white one instead of the semi transparent white one.

However setting in share_menu.xml and code doesn't work. Just wondering whether anyone has got workaround for this before extending the ShareActionProvider. (I'm using actionbarsherlock)

@Override
public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
    inflater.inflate(R.menu.share_menu, menu);
    MenuItem actionItem = menu.findItem(R.id.share_action_provider);

    ShareActionProvider actionProvider = (ShareActionProvider) actionItem.getActionProvider();
     actionProvider.setShareIntent(mShareIntent);

    // re-setting the icon as it's not being picked up from the menu xml file
    actionItem.setIcon(R.drawable.ic_action_share);

    super.onCreateOptionsMenu(menu, inflater);

}

share_menu.xml

 <item android:id="@+id/share_action_provider"
        android:showAsAction="ifRoom"
        android:title="@string/share_with"
        android:icon="@drawable/ic_action_share"
        android:actionProviderClass="com.actionbarsherlock.widget.ShareActionProvider" />

Update: Also tried setting it in the style, but no joy

<style name="Theme.MyApp" parent="Theme.Sherlock.Light">
        <item name="actionModeStyle">@style/ActionModeStyle</item>
        <item name="android:actionModeStyle">@style/ActionModeStyle</item>
</style>

<style name="ActionModeStyle" parent="Widget.Sherlock.ActionMode">
      <item name="actionModeShareDrawable">@drawable/ic_action_share</item>
  </style>

When I am looking to customize the action bar, usually the first place I look is the ActionBarSherlock themes and styles.

I found that the Sherlock theme uses the "actionModeShareDrawable" as found in theme.xml file.

Try changing your theme to include the "actionModeShareDrawable" item directly.

<style name="Theme.MyApp" parent="Theme.Sherlock.Light">
    <item name="actionModeShareDrawable">@drawable/ic_action_share</item>
</style>