我希望在我的一项活动中使用操作栏共享提供程序,并且我将 Theme.Sherlock.Light.DarkActionBar 作为 baseTheme。
这是我如何在活动中创建共享选项:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
ShareActionProvider provider = new ShareActionProvider(getSupportActionBar().getThemedContext());
provider.setShareHistoryFileName(ShareActionProvider.DEFAULT_SHARE_HISTORY_FILE_NAME);
provider.setShareIntent(createShareIntent());
menu.add(Menu.NONE, SHARE_ACTION_ID, 0,
getString(R.string.action_share))
.setIcon(R.drawable.icon_share_white)
.setActionProvider(provider)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
return super.onCreateOptionsMenu(menu);
}
private Intent createShareIntent() {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, url);
return shareIntent;
}
这是我的基本主题:
<style name="AppBaseTheme" parent="Theme.Sherlock.Light.DarkActionBar">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="actionBarItemBackground">@drawable/action_item_background_selector</item>
<item name="android:actionBarItemBackground">@drawable/action_item_background_selector</item>
</style>
应用程序与 Theme.Sherlock 一起工作得很好,但是当我使用我的 AppTheme 时,它给了我这个错误:
FATAL EXCEPTION: main
android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.content.res.Resources.getValue(Resources.java:1026)
at android.content.res.Resources.getDrawable(Resources.java:671)
at com.actionbarsherlock.widget.ShareActionProvider.onCreateActionView(ShareActionProvider.java:170)
at com.actionbarsherlock.internal.view.ActionProviderWrapper.onCreateActionView(ActionProviderWrapper.java:23)
at android.view.ActionProvider.onCreateActionView(ActionProvider.java:98)
at com.android.internal.view.menu.MenuItemImpl.getActionView(MenuItemImpl.java:580)
at com.android.internal.view.menu.ActionMenuPresenter.getItemView(ActionMenuPresenter.java:264)
at com.android.internal.view.menu.ActionMenuPresenter.flagActionItems(ActionMenuPresenter.java:555)
at com.android.internal.view.menu.MenuBuilder.flagActionItems(MenuBuilder.java:1048)
at com.android.internal.view.menu.BaseMenuPresenter.updateMenuView(BaseMenuPresenter.java:91)
at com.android.internal.view.menu.ActionMenuPresenter.updateMenuView(ActionMenuPresenter.java:297)
at com.android.internal.view.menu.MenuBuilder.dispatchPresenterUpdate(MenuBuilder.java:244)
at com.android.internal.view.menu.MenuBuilder.onItemsChanged(MenuBuilder.java:946)
at com.android.internal.view.menu.MenuBuilder.startDispatchingItemsChanged(MenuBuilder.java:969)
at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:498)
at com.android.internal.policy.impl.PhoneWindow.invalidatePanelMenu(PhoneWindow.java:829)
at com.android.internal.policy.impl.PhoneWindow$1.run(PhoneWindow.java:3192)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4921)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
at dalvik.system.NativeStart.main(Native Method)
我已经看到了很多这类问题和他们接受的回答,但没有运气。知道如何解决这个问题吗?提前致谢。
编辑: 在 style.xml 中从 AppTheme 中删除“actionBarItemBackground”这些属性也可以,但我需要动作栏也有自定义背景......那么解决方案可能是什么?