Android: The margin between the ActionBar and the Navigation drop-down menu changes when you click the Search button.

I have the following setup:

On launch

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

Searching

So, if you performed a search, you can click the Home icon to close the panel:

Reverting

But when you return, the drop-down navigation menu is shifted to the right quite a bit:

Wrong!

I can not understand what is happening here. The first thing I did was make a new application and recreate it (this is what you see below) to make sure that this is not a problem with the styles or themes that I use in my main application. This did not help solve this problem. I use ActionBarSherlock, so the next thing I did was rebuild the project using the official Action API. It didn't matter either.

Does anyone have any ideas? I will provide any code that you guys can help, but I have almost fully implemented it in Google docs. Thanks!

EDIT: add some images before and after images with visible layout boundaries (option parameters in 4.1 +)

BEFORE:

good

AFTER:

bad

I also added an XML menu:

<?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"/> 

+6
source share
1 answer

Problem detected. I gave the action bar the name "". Instead, if you provided the action bar with this display option:

actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME);

he fixed the problem. Hope this helps someone else.

+3
source

Source: https://habr.com/ru/post/923704/


All Articles