Actionbar Sherlock Search Widget expand does not work
actionbarsherlock, android, user-interface
Solution
After going through the source documentation I finally found the answer by myself. `menuItem.expandActionView()` only takes effect if the MenuItem has set the following flag: `searchItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);`
Hope that helps somebody out there!
Problem
I'm using Actionbar Sherlock. The activity be shown on startup should start in a "search mode" to start searching immediately. For doing so I use the following code: ``` @Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); //collapse search MenuItem searchItem = menu.add(Menu.NONE, R.string.inlineSearch, Menu.NONE, getString(R.string.inlineSearch)).setIcon(R.drawable.menu_search); searchItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); searchView = new SearchView(this); searchItem.setActionView(new SearchView(this)); searchItem.expandActionView(); return true; } ``` The SearchView is the View provided by Android / Actionbar Sherlock. The problem I'm facing with that is that no matter what I do, the item is never expanded on startup. I tried calling the expandActionView method after startup by using another actionbar item, nothing changed. I implemented my own View implementing CollapsibleActionView, but the methods onActionViewExpanded() and onActionViewCollapsed() never get called. But if I click the collapsed button of the SearchView, the view expands as expected. Does anyone know what I'm doing wrong? Thanks for your help!