【发布时间】:2013-09-26 20:18:21
【问题描述】:
我在我的项目中使用 ActionBarSherlock,并想设置一个分享按钮以在 FB 等上发布内容......我通过这种方式实现了这一点:Adding items to action bar (using ActionBarSherlock)
您可能知道,ShareActionProvider 添加了第二个图标,其中包含最常用的共享选项。这意味着另一个应用程序的图标出现在我的操作栏中,我想阻止这种行为......我已经看到了 2 种可能的解决方案,但不幸的是,这两种方法都对我不起作用:/
第一次尝试是在我的目标类中实现 OnShareTargetSelectedListener 并覆盖 onShareTargetSelected 方法(如这里:ActionBarSherlock - Share Content icon issue)。但是额外的图标仍然存在......这是我的代码:
@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 重写一些类,以防止它显示额外的图标(如这里:How to hide the share action (which use most) icon near the share action provider?)。但是我遇到了这个解决方案的问题,因为我无法从我的自定义类中导入 com.actionbarsherlock.widget.ActivityChooserModel (阻止到外部包)。即使将此类复制到我的包中,它也不起作用(应用程序崩溃)...
看起来禁用这个额外的图标是一件很平常的事情,但我不明白为什么上面的解决方案对我不起作用......
提前感谢您的任何想法和建议
【问题讨论】:
-
您的第二个解决方案是我推荐的方法。 “即使将这个类复制到我的包中,它也不起作用(应用程序崩溃)”——使用 LogCat 检查与您的崩溃相关的 Java 堆栈跟踪。 “看起来禁用这个额外的图标是一件很平常的事情”——你的证明是......究竟是什么?
标签: android android-actionbar actionbarsherlock