On Ice Cream Sandwich:
I'm looking to add an AutoCompleteTextView to an ActionBar through the standard Action View mechanism (because SearchView isn't available pre-ICS and I'm also using ActionBarSherlock):
<item android:id="@+id/menu_search" android:actionViewClass="com.example.AutoCompleteActionView" android:showAsAction="ifRoom" android:title="@string/address"></item>
<item android:id="@+id/menu_close" android:icon="@drawable/ic_menu_close_clear_cancel" android:showAsAction="always"></item>
<item android:id="@+id/menu_ok" android:icon="@drawable/ic_menu_ok" android:showAsAction="always"></item>
This works, however by default it does not consume the available space in the ActionBar, which I would like.
I've looked at the source for the SearchView and seen how it overrides onMeasure, and done the same thing for my own class that I derived from AutoCompleteTextView. When I do this, the AutoCompleteTextView consumes all the space, leaving no space for two menu items I want to display to the right of it.
It looks as though the width returned from MeasureSpec.getSize() does not take into account the other two menu items when the MeasureSpec.getMode() is MeasureSpec.AT_MOST.
Anyone done anything similar? Any suggestions?
Thanks, Damian
I think this could help:
Create a collapsible menu item with a custom layout:
This is the custom layout:
Then in your activity:
I wasn't able to get Matthias's suggestion to work in code (maybe I was missing something), but adding a minWidth attribute to the topmost element in my Action View did the trick.
Credit to this post: Make an Android ActionBar's ActionView's Width match the ActionBar's width. This will make it stretch.
might be light years late, but if someone comes looking do the following on your action views to get them styled as the default action bar icons,
This helps you?: