Edit: DrawerArrowDrawable
needs to override getConstantState
or it will throw a NullPointerException
here: https://github.com/android/platform_frameworks_base/blob/kitkat-release/core/java/com/android/internal/widget/ActionBarView.java#L1637
I am using DrawerArrowDrawable
with SlidingMenu and it works great. However, when I tried adding android.widget.SearchView
in the menu it crashes the app.
E/AndroidRuntime( 4635): java.lang.NullPointerException
E/AndroidRuntime( 4635): at com.android.internal.widget.ActionBarView$ExpandedActionViewMenuPresenter.expandItemActionView(ActionBarView.java:1711)
E/AndroidRuntime( 4635): at com.android.internal.view.menu.MenuBuilder.expandItemActionView(MenuBuilder.java:1236)
E/AndroidRuntime( 4635): at com.android.internal.view.menu.MenuItemImpl.expandActionView(MenuItemImpl.java:625)
E/AndroidRuntime( 4635): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:879)
E/AndroidRuntime( 4635): at com.android.internal.view.menu.ActionMenuView.invokeItem(ActionMenuView.java:558)
E/AndroidRuntime( 4635): at com.android.internal.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:187)
E/AndroidRuntime( 4635): at com.htc.internal.widget.HtcScaleAnimController.onClick(HtcScaleAnimController.java:334)
E/AndroidRuntime( 4635): at android.view.View.performClick(View.java:4480)
E/AndroidRuntime( 4635): at android.view.View$PerformClick.run(View.java:18686)
E/AndroidRuntime( 4635): at android.os.Handler.handleCallback(Handler.java:733)
E/AndroidRuntime( 4635): at android.os.Handler.dispatchMessage(Handler.java:95)
E/AndroidRuntime( 4635): at android.os.Looper.loop(Looper.java:157)
E/AndroidRuntime( 4635): at android.app.ActivityThread.main(ActivityThread.java:5872)
E/AndroidRuntime( 4635): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 4635): at java.lang.reflect.Method.invoke(Method.java:515)
E/AndroidRuntime( 4635): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:852)
E/AndroidRuntime( 4635): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:668)
E/AndroidRuntime( 4635): at dalvik.system.NativeStart.main(Native Method)
To reproduce this issue:
- Create a new
Activity
.
- Set DrawerArrowDrawable as the ActionBar icon:
getActionBar().setIcon(new DrawerArrowDrawable(getResources()));
- Add a
SearchView
to the ActionBar
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/search"
android:actionViewClass="android.widget.SearchView"
android:icon="@drawable/ic_action_search"
android:showAsAction="ifRoom|collapseActionView"
android:title="@string/search"/>
</menu>
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.options_menu, menu);
return true;
}
- Click on the search
MenuItem
that should display the SearchView
in the action bar,