设置在动作条ShareActionProvider一个自定义的共享图标 [英] Setting a custom share icon on Actionbar ShareActionProvider

查看:259
本文介绍了设置在动作条ShareActionProvider一个自定义的共享图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置图标ShareActionProvider,需要一个坚实的白色的,而不是半透明白色的。

然而,在share_menu.xml和code没有工作环境。只是想知道是否有人已经得到了解决此扩展ShareActionProvider之前。 (我使用actionbarsherlock)

  @覆盖
公共无效onCreateOptionsMenu(最后菜单菜单,最后MenuInflater充气){
    inflater.inflate(R.menu.share_menu,菜单);
    菜单项actionItem = menu.findItem(R.id.share_action_provider);

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

    //重新设置图标,它没有被拾起从菜单中的XML文件
    actionItem.setIcon(R.drawable.ic_action_share);

    super.onCreateOptionsMenu(菜单,充气);

}
 

share_menu.xml

 <项目机器人:ID =@ + ID / share_action_provider
        机器人:showAsAction =ifRoom
        机器人:标题=@字符串/ share_with
        机器人:图标=@可绘制/ ic_action_share
        机器人:actionProviderClass =com.actionbarsherlock.widget.ShareActionProvider/>
 

更新: 还试图在风格上设置它,但没有喜悦

 <样式名称=Theme.MyApp父=Theme.Sherlock.Light>
        <项目名称=actionModeStyle> @风格/ ActionModeStyle< /项目>
        <项目名称=机器人:actionModeStyle> @风格/ ActionModeStyle< /项目>
< /风格>

<样式名称=ActionModeStyle父=Widget.Sherlock.ActionMode>
      <项目名称=actionModeShareDrawable> @可绘制/ ic_action_share< /项目>
  < /风格>
 

解决方案

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

我发现福尔摩斯主题使用actionModeShareDrawable在<一个发现href="https://github.com/JakeWharton/ActionBarSherlock/blob/master/library/res/values/abs__themes.xml#L43">theme.xml文件。

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

 &LT;样式名称=Theme.MyApp父=Theme.Sherlock.Light&GT;
    &LT;项目名称=actionModeShareDrawable&GT; @可绘制/ ic_action_share&LT; /项目&GT;
&LT; /风格&GT;
 

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>

这篇关于设置在动作条ShareActionProvider一个自定义的共享图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆