代码如下:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getSupportMenuInflater().inflate(R.menu.main, menu);
MenuItem item = menu.findItem(R.id.share);
ShareActionProvider provide = (ShareActionProvider) item.getActionProvider();
provide.setShareHistoryFileName(ShareActionProvider.DEFAULT_SHARE_HISTORY_FILE_NAME);
provide.setShareIntent(getShareIntent());
return super.onCreateOptionsMenu(menu);
}
menu文件内容:
android:id="@+id/share"
android:actionProviderClass="com.actionbarsherlock.widget.ShareActionProvider"
android:icon="@android:drawable/ic_menu_share"
android:showAsAction="always"
android:title="@string/share"
android:titleCondensed="@string/share">
报错内容如下:
02-27 11:20:08.027: E/AndroidRuntime(16015): FATAL EXCEPTION: main
02-27 11:20:08.027: E/AndroidRuntime(16015): android.view.InflateException: Binary XML file line #26: Error inflating class
02-27 11:20:08.027: E/AndroidRuntime(16015): at android.view.LayoutInflater.createView(LayoutInflater.java:613)
02-27 11:20:08.027: E/AndroidRuntime(16015): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
02-27 11:20:08.027: E/AndroidRuntime(16015): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
02-27 11:20:08.027: E/AndroidRuntime(16015): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
02-27 11:20:08.027: E/AndroidRuntime(16015): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
02-27 11:20:08.027: E/AndroidRuntime(16015): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
02-27 11:20:08.027: E/AndroidRuntime(16015): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
02-27 11:20:08.027: E/AndroidRuntime(16015): at com.actionbarsherlock.widget.ActivityChooserView.(ActivityChooserView.java:229)
02-27 11:20:08.027: E/AndroidRuntime(16015): at com.actionbarsherlock.widget.ActivityChooserView.(ActivityChooserView.java:202)
02-27 11:20:08.027: E/AndroidRuntime(16015): at com.actionbarsherlock.widget.ActivityChooserView.(ActivityChooserView.java:192)
02-27 11:20:08.027: E/AndroidRuntime(16015): at com.actionbarsherlock.widget.ShareActionProvider.onCreateActionView(ShareActionProvider.java:164)
02-27 11:20:08.027: E/AndroidRuntime(16015): at com.actionbarsherlock.internal.view.ActionProviderWrapper.onCreateActionView(ActionProviderWrapper.java:23)
02-27 11:20:08.027: E/AndroidRuntime(16015): at android.view.ActionProvider.onCreateActionView(ActionProvider.java:98)
02-27 11:20:08.027: E/AndroidRuntime(16015): at com.android.internal.view.menu.MenuItemImpl.getActionView(MenuItemImpl.java:580)
02-27 11:20:08.027: E/AndroidRuntime(16015): at com.android.internal.view.menu.ActionMenuPresenter.getItemView(ActionMenuPresenter.java:155)
02-27 11:20:08.027: E/AndroidRuntime(16015): at com.android.internal.view.menu.ActionMenuPresenter.flagActionItems(ActionMenuPresenter.java:404)
02-27 11:20:08.027: E/AndroidRuntime(16015): at com.android.internal.view.menu.MenuBuilder.flagActionItems(MenuBuilder.java:1048)
02-27 11:20:08.027: E/AndroidRuntime(16015): at com.android.internal.view.menu.BaseMenuPresenter.updateMenuView(BaseMenuPresenter.java:87)
02-27 11:20:08.027: E/AndroidRuntime(16015): at com.android.internal.view.menu.ActionMenuPresenter.updateMenuView(ActionMenuPresenter.java:188)
02-27 11:20:08.027: E/AndroidRuntime(16015): at com.android.internal.view.menu.MenuBuilder.dispatchPresenterUpdate(MenuBuilder.java:244)
02-27 11:20:08.027: E/AndroidRuntime(16015): at com.android.internal.view.menu.MenuBuilder.onItemsChanged(MenuBuilder.java:946)
02-27 11:20:08.027: E/AndroidRuntime(16015): at com.android.internal.view.menu.MenuBuilder.startDispatchingItemsChanged(MenuBuilder.java:969)
02-27 11:20:08.027: E/AndroidRuntime(16015): at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:442)
02-27 11:20:08.027: E/AndroidRuntime(16015): at com.android.internal.policy.impl.PhoneWindow.invalidatePanelMenu(PhoneWindow.java:753)
02-27 11:20:08.027: E/AndroidRuntime(16015): at com.android.internal.policy.impl.PhoneWindow$1.run(PhoneWindow.java:2926)
02-27 11:20:08.027: E/AndroidRuntime(16015): at android.os.Handler.handleCallback(Handler.java:615)
02-27 11:20:08.027: E/AndroidRuntime(16015): at android.os.Handler.dispatchMessage(Handler.java:92)
02-27 11:20:08.027: E/AndroidRuntime(16015): at android.os.Looper.loop(Looper.java:213)
02-27 11:20:08.027: E/AndroidRuntime(16015): at android.app.ActivityThread.main(ActivityThread.java:4786)
02-27 11:20:08.027: E/AndroidRuntime(16015): at java.lang.reflect.Method.invokeNative(Native Method)
02-27 11:20:08.027: E/AndroidRuntime(16015): at java.lang.reflect.Method.invoke(Method.java:511)
02-27 11:20:08.027: E/AndroidRuntime(16015): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
02-27 11:20:08.027: E/AndroidRuntime(16015): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
02-27 11:20:08.027: E/AndroidRuntime(16015): at dalvik.system.NativeStart.main(Native Method)
02-27 11:20:08.027: E/AndroidRuntime(16015): Caused by: java.lang.reflect.InvocationTargetException
02-27 11:20:08.027: E/AndroidRuntime(16015): at java.lang.reflect.Constructor.constructNative(Native Method)
02-27 11:20:08.027: E/AndroidRuntime(16015): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
02-27 11:20:08.027: E/AndroidRuntime(16015): at android.view.LayoutInflater.createView(LayoutInflater.java:587)
02-27 11:20:08.027: E/AndroidRuntime(16015): ... 33 more
02-27 11:20:08.027: E/AndroidRuntime(16015): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x2/d=0x7f01000f a=-1}
02-27 11:20:08.027: E/AndroidRuntime(16015): at android.content.res.Resources.loadDrawable(Resources.java:1897)
02-27 11:20:08.027: E/AndroidRuntime(16015): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
02-27 11:20:08.027: E/AndroidRuntime(16015): at android.view.View.(View.java:3392)
02-27 11:20:08.027: E/AndroidRuntime(16015): at android.view.ViewGroup.(ViewGroup.java:460)
02-27 11:20:08.027: E/AndroidRuntime(16015): at android.widget.FrameLayout.(FrameLayout.java:105)
02-27 11:20:08.027: E/AndroidRuntime(16015): at android.widget.FrameLayout.(FrameLayout.java:101)
02-27 11:20:08.027: E/AndroidRuntime(16015): ... 36 more
解决办法: 在相应的activity里面添加主题样式android:theme="@style/Theme.Sherlock"