如果我使用:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getSupportMenuInflater().inflate(R.menu.main_menu, menu);
com.actionbarsherlock.widget.SearchView searchView = new com.actionbarsherlock.widget.SearchView(Activity_TimetablePager.this);
...
系统崩溃并显示以下日志:
06-22 18:18:23.384: D/SherlockFragmentActivity(3613): [onCreatePanelMenu] featureId: 0, menu: com.android.internal.view.menu.MenuBuilder@af2ca820
06-22 18:18:23.384: D/ActionBarSherlock(3613): [dispatchCreateOptionsMenu] menu: com.android.internal.view.menu.MenuBuilder@af2ca820
06-22 18:18:23.384: D/ActionBarSherlock(3613): [callbackCreateOptionsMenu] menu: com.actionbarsherlock.internal.view.menu.MenuWrapper@af2cc5c8
06-22 18:18:23.384: D/Watson(3613): [onCreatePanelMenu] featureId: 0, menu: com.actionbarsherlock.internal.view.menu.MenuWrapper@af2cc5c8
06-22 18:18:23.384: D/SherlockFragmentActivity(3613): [getSupportMenuInflater]
06-22 18:18:23.384: D/ActionBarSherlock(3613): [getMenuInflater]
06-22 18:18:23.384: D/ActionBarSherlock(3613): [getActionBar]
06-22 18:18:23.384: D/AndroidRuntime(3613): Shutting down VM
06-22 18:18:23.384: W/dalvikvm(3613): threadid=1: thread exiting with uncaught exception (group=0xaecd1908)
06-22 18:18:23.384: E/AndroidRuntime(3613): FATAL EXCEPTION: main
06-22 18:18:23.384: E/AndroidRuntime(3613): android.view.InflateException: Binary XML file line #29: Error inflating class <unknown>
06-22 18:18:23.384: E/AndroidRuntime(3613): at android.view.LayoutInflater.createView(LayoutInflater.java:613)
06-22 18:18:23.384: E/AndroidRuntime(3613): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
这适用于 Android 2.3,但不适用于 4.x。我正在使用 ActionBarSherlock 4.3.1,在本例中是在 viewPager 活动中。这是一个已知的问题?
(目前我有一个解决方法,我在 4.x 中使用默认的 android SearchView。)