What event(s) I should listen to determine when user clicks on iconified SearchView. I want to remove some items (ActionBar navigation tabs, if that is important) from action bar to make more space in portrait orientation.
I've tried OnClickListener, OnFocusChangeListener, OnTouchListener and other events but neither gets triggered by SearchView expansion.
Since API Level 14 you have a dedicated listener: http://developer.android.com/guide/topics/ui/actionbar.html
  @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.options, menu);
        MenuItem menuItem = menu.findItem(R.id.actionItem);
        ...
    menuItem.setOnActionExpandListener(new OnActionExpandListener() {
        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            // Do something when collapsed
            return true;       // Return true to collapse action view
        }
        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            // Do something when expanded
            return true;      // Return true to expand action view
        }
    });
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With