Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Margin between ActionBar icon and Navigation dropdown menu changes when you click search

I have the following setup:

On launch

So you can click on the search icon for the action bar to turn into a search bar. Pretty standard:

Searching

So if you're done searching you can click the Home icon to make the bar go away:

Reverting

But when you go back, the navigation dropdown menu is shifted to the right quite a bit:

Wrong!

I can't really figure out what is happening here. The first thing I did was make a brand new app and recreate it (which is what you see below) to make sure it wasn't an issue with styles or themes I'm using in my main app. That didn't help the problem. I'm using ActionBarSherlock, so the next thing I did was rebuild the project using Google's official Action Bar API. That didn't make a difference either.

Does anyone have any ideas? I'll provide any code you guys think could help, but I took the implementation pretty much straight from Google's docs about it. Thanks!

EDIT: Adding some before-after images with layout borders visible (dev options feature in 4.1+)

BEFORE:

good

AFTER:

bad

I've also included the menu XML:

<?xml version="1.0" encoding="utf-8"?>

<item android:id="@+id/abm_search"
    android:icon="@android:drawable/ic_menu_search"
    android:showAsAction="always|collapseActionView"
    android:actionViewClass="android.widget.SearchView" />

<item android:id="@+id/abm_location"
    android:title="Stuff"
    android:showAsAction="never" />

<item android:id="@+id/abm_radius"
    android:title="More Stuff"
    android:showAsAction="never" />

<item android:id="@+id/abm_settings"
    android:title="Other Stuff"
    android:showAsAction="never"/>

like image 464
JMRboosties Avatar asked Aug 24 '12 19:08

JMRboosties


1 Answers

Found out the problem. I had given the action bar a title of "". Instead, if you gave the action bar this display option:

actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME);

it fixed the problem. Hope this helps someone else.

like image 171
JMRboosties Avatar answered Nov 15 '22 05:11

JMRboosties