我正在尝试以编程方式设置菜单,我的方法将 com.actionbarsherlock.view.Menu 菜单作为参数。当我想更改菜单项的样式时,我正在尝试设置 SpannableString 可跨越并将其传递给添加。menu.add(0, MENU_ABOUT, 0, spannable); 当我点击该菜单项时,这只会在 ICS 中导致崩溃。如果我遗漏了什么,有什么想法。谢谢 这是我正在尝试的代码,当我运行应用程序并选择“关于应用程序”时它崩溃了。仅供参考,我使用 SpannableString 是因为我想为菜单项添加一些样式和颜色。如果我使用常规字符串,则不会发生崩溃,但是我无法进行样式设置
public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu)
{
SpannableString spannable = new SpannableString("About Application");
menu.add(0, MENU_ABOUT, 0, spannable);
return true;
}
这是堆栈跟踪:
09-05 02:25:32.849: E/AndroidRuntime(684): FATAL EXCEPTION: main
09-05 02:25:32.849: E/AndroidRuntime(684): java.lang.IllegalArgumentException: Invalid payload item type
09-05 02:25:32.849: E/AndroidRuntime(684): at android.util.EventLog.writeEvent(Native Method)
09-05 02:25:32.849: E/AndroidRuntime(684): at android.app.Activity.onMenuItemSelected(Activity.java:2501)
09-05 02:25:32.849: E/AndroidRuntime(684): at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:351)
09-05 02:25:32.849: E/AndroidRuntime(684): at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:950)
09-05 02:25:32.849: E/AndroidRuntime(684): at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
09-05 02:25:32.849: E/AndroidRuntime(684): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
09-05 02:25:32.849: E/AndroidRuntime(684): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
09-05 02:25:32.849: E/AndroidRuntime(684): at com.android.internal.view.menu.ListMenuPresenter.onItemClick(ListMenuPresenter.java:163)
09-05 02:25:32.849: E/AndroidRuntime(684): at android.widget.AdapterView.performItemClick(AdapterView.java:292)
09-05 02:25:32.849: E/AndroidRuntime(684): at android.widget.AbsListView.performItemClick(AbsListView.java:1058)
09-05 02:25:32.849: E/AndroidRuntime(684): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2514)
09-05 02:25:32.849: E/AndroidRuntime(684): at android.widget.AbsListView.onTouchEvent(AbsListView.java:3180)
09-05 02:25:32.849: E/AndroidRuntime(684): at android.view.View.dispatchTouchEvent(View.java:5541)
09-05 02:25:32.849: E/AndroidRuntime(684): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1951)
09-05 02:25:32.849: E/AndroidRuntime(684): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1712)
09-05 02:25:32.849: E/AndroidRuntime(684): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)
09-05 02:25:32.849: E/AndroidRuntime(684): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726)
09-05 02:25:32.849: E/AndroidRuntime(684): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1860)
09-05 02:25:32.849: E/AndroidRuntime(684): at android.view.View.dispatchPointerEvent(View.java:5721)
09-05 02:25:32.849: E/AndroidRuntime(684): at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:2890)
09-05 02:25:32.849: E/AndroidRuntime(684): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2466)
09-05 02:25:32.849: E/AndroidRuntime(684): at android.view.ViewRootImpl.processInputEvents(ViewRootImpl.java:845)
09-05 02:25:32.849: E/AndroidRuntime(684): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2475)
09-05 02:25:32.849: E/AndroidRuntime(684): at android.os.Handler.dispatchMessage(Handler.java:99)
09-05 02:25:32.849: E/AndroidRuntime(684): at android.os.Looper.loop(Looper.java:137)
09-05 02:25:32.849: E/AndroidRuntime(684): at android.app.ActivityThread.main(ActivityThread.java:4424)
09-05 02:25:32.849: E/AndroidRuntime(684): at java.lang.reflect.Method.invokeNative(Native Method)
09-05 02:25:32.849: E/AndroidRuntime(684): at java.lang.reflect.Method.invoke(Method.java:511)
09-05 02:25:32.849: E/AndroidRuntime(684): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
09-05 02:25:32.849: E/AndroidRuntime(684): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
09-05 02:25:32.849: E/AndroidRuntime(684): at dalvik.system.NativeStart.main(Native Method)
谢谢