在动作条删除多余的图标(使用ShareActionProvider和ActionBarSherlock时) [英] Remove extra icon at actionbar (when using ShareActionProvider and ActionBarSherlock)

查看:143
本文介绍了在动作条删除多余的图标(使用ShareActionProvider和ActionBarSherlock时)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用ActionBarSherlock在我的项目,并要设置一个共享按钮将其发布内容的FB等等...我实现了这种方式:<一href="http://stackoverflow.com/questions/19013294/adding-items-to-action-bar-using-actionbarsherlock/">Adding项目操作栏(使用ActionBarSherlock)

I'm using ActionBarSherlock in my project, and want to set a share button to post content at FB etc etc... I achieved that this way: Adding items to action bar (using ActionBarSherlock)

正如你可能知道,ShareActionProvider增加了第二个图标,最常用的选项共享。这意味着其他应用程序的图标会出现在我的行​​动吧,我想prevent这种行为。我已经看到了这2种可能的解决方案,可惜两人都没有工作对我来说:/

As you may know, ShareActionProvider adds a second icon with the most used option for sharing. That means another app's icon is appearing in my action bar, and I want to prevent that behavior... I've seen 2 possible solutions for that, and unfortunately both didn't worked to me :/

第一次尝试,我的目标类,实现OnShareTargetSelectedListener并覆盖onShareTargetSelected的方法(比如这里:<一href="http://stackoverflow.com/questions/11067829/actionbarsherlock-share-content-icon-issue">ActionBarSherlock - 共享内容的图标问题)。但额外的图标在那里停留......这是我的code:

The first attempt was, in my target class, to implement OnShareTargetSelectedListener and override onShareTargetSelected method (like here: ActionBarSherlock - Share Content icon issue). But the extra icon stays there... here is my code:

@Override
public boolean onCreateOptionsMenu(Menu menu)
{
    getSupportMenuInflater().inflate(R.menu.share, menu);
    mShareActionProvider = (ShareActionProvider) menu.findItem(R.id.share).getActionProvider();
    Intent intent = getDefaultShareIntent();
    mShareActionProvider.setOnShareTargetSelectedListener(this);
    if(intent!=null)
        mShareActionProvider.setShareIntent(intent);
    return super.onCreateOptionsMenu(menu);
}

@Override
public boolean onShareTargetSelected(ShareActionProvider source,
                                     Intent intent) {
    this.startActivity(intent);
    // started activity ourself to prevent search history
    return true;
}

在第二次尝试改写从ActionBarSherlock一些类,以prevent它显示额外的图标(喜欢这里:<一href="http://stackoverflow.com/questions/15755465/how-to-hide-the-share-action-which-use-most-icon-near-the-share-action-provide/">How隐藏共享行动(其中使用最多的)图标附近的占有率行动提供商?)。但我有问题,这个解决方案,因为我无法从我的自定义类进口com.actionbarsherlock.widget.ActivityChooserModel(受阻于外包装)。甚至抄袭该类我的包,它没有工作(应用程序崩溃)...

The second attempt was to rewrite some classes from ActionBarSherlock, to prevent it from showing the extra icon (like here: How to hide the share action (which use most) icon near the share action provider?). But I got problems with this solution, as I couldn't import com.actionbarsherlock.widget.ActivityChooserModel from my custom classes (blocked to outer packages). Even copying this class to my package, it didn't worked (app crashes)...

看起来像它的一个pretty的平常的事情来禁用这些额外的图标,但我不明白,为什么上面没有工作给我的解决方案...

Looks like its a pretty usual thing to disable this extra icon, but I couldn't figure out why the solutions above didn't worked to me...

在此先感谢您的任何想法和sugestions

Thanks in advance for any ideas and sugestions

推荐答案

我不知道,如果你解决你的问题,但我有同样的问题,以消除历史 ShareActionProvider 。我尝试了一切,并在不久的答案,我发现是一样的,你(如何隐藏共享操作图标?)。< BR> 一些研究之后,我发现这招的第二点意见:
操作栏福尔摩斯拥有德preciated方法

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

  1. 复制/粘贴在 3班 ShareActionProvider ActivityChooserView ActivityChooverModel )从ABS到您的包。
  2. 替代进口由你用自己的包。
  3. 更改行如果(activityCount&GT; 0安培;&安培; historySize&GT; 0)如果(假)在新的 ActivityChooserView
    (你会得到一个错误:setActived不适用于当前版本)
  4. 保存并关闭类。
  5. 替换类在menu.xml文件的项目由安卓actionProviderClass =com.myapp.ShareActionProvider
  6. 清单,使的minSdkVersion 等于11.保存项目。清洁。
  7. 返回到你的清单,由旧的,你用你的替换的minSdkVersion 。保存和清洁。
  1. Copy/Paste the 3 classes (ShareActionProvider, ActivityChooserView and ActivityChooverModel) from ABS to your package.
  2. Replace the import by yours with your own package.
  3. Change the line if (activityCount > 0 && historySize > 0) by if (false) in your new ActivityChooserView.
    (You will get an error: "setActived" is not available for your current version)
  4. Save it and close the class.
  5. Replace the class in your menu.xml your item by android:actionProviderClass="com.myapp.ShareActionProvider"
  6. In your Manifest, make the minSdkVersion equals to 11. Save your project. Clean it.
  7. Return to your Manifest, replace your minSdkVersion by the old one you used. Save and clean.

它完美。让我知道这个技巧解决你的问题。

It works perfectly. Let me know if this tip resolved your problem.

这篇关于在动作条删除多余的图标(使用ShareActionProvider和ActionBarSherlock时)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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