My question is closely related to SearchView wrong alignment and SearchView positions when expanded in ActionBar but the answers posted there do not work.
So, I'm using a SearchView in the Action Bar:
<item android:id="@+id/action_search"
android:icon="@drawable/navi_search"
android:title="@string/action_search"
android:showAsAction="ifRoom|collapseActionView"
android:actionViewClass="android.widget.SearchView"
/>
It looks like this by default (top-right corner, next to overflow menu):
Problem is, when expanded, I'd like the SearchView to stay on the right, but instead, it moves to the left edge, next to home button (app icon).
I tried changing showAsAction
to either of these (as suggested here):
android:showAsAction="ifRoom"
android:showAsAction="always"
...And that does fix the alignment when expanded, but the custom icon is lost when in collapsed state:
Also, stuff like android:layout_alignParentRight="true"
and android:layout_centerInParent="true"
on the menu <item>
have no effect.
Any ideas?
I'm targetting Android 4.0 and above:
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="19" />
android:gravity="right"
on the SearchView<item>
in menu XML would achieve this too, but at least on my test devices it does not. – Audette