Organizational Research By

Surprising Reserch Topic

searchview expansion style dependent on items order using -'android,searchview,android-toolbar'


searchview expansion style dependent on items order  using -'android,searchview,android-toolbar'

I'm using SearchView (support.v7) in my Toolbar and I'm facing following problem. When I set position of search icon as most right icon, three rectangle icon is shown on left.

In case I put search icon as left most icon, ActionView with search replaces almost whole Toolbar a and hides three rectangle icon. I want to reach Toolbar 1 action items order but with Toolbar 2 expansion style.

Toolbar 1:

Toolbar 1 - expanded:


Toolbar 2:

Toolbar 2 - expanded:


Menu creation:

@Override
public void onCreateOptionsMenu(final Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.menu_search, menu); // just switching these 2 lines
    inflater.inflate(R.menu.menu_nearby, menu); // to reach different expansion styles

    // show only one of two icons in menu_nearby
    menu.findItem(R.id.menu_list).setVisible(!listVisible);
    menu.findItem(R.id.menu_map).setVisible(listVisible);

    final SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.menu_search));
    final MyAdapter adapter = new MyAdapter(getActivity());
    searchView.setSuggestionsAdapter(adapter);
}


menu_search.xml:

<menu
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/menu_search"
        android:icon="@drawable/ic_menu_search"
        android:title="@string/menu_search"
        app:actionViewClass="android.support.v7.widget.SearchView"
        app:showAsAction="always"/>
</menu>


menu_nearby.xml:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/menu_map"
        android:title="@string/map"
        android:icon="@drawable/ic_map"
        app:showAsAction="always"/>

    <item
        android:id="@+id/menu_list"
        android:title="@string/list"
        android:icon="@drawable/ic_nearby_list"
        app:showAsAction="always"/>
</menu>


SearchView style in styles.xml:

<style name="SearchViewStyle" parent="Widget.AppCompat.SearchView">
    <item name="closeIcon">@drawable/ic_cancel_search</item>
    <item name="searchIcon">@drawable/ic_menu_search</item>
    <item name="queryBackground">@drawable/bg_search_view</item>
    <item name="queryHint">@string/search_term</item>
</style>


It is really interesting, why SearchView moves (probably) right items out of screen, but left ones stays on its positions. Thanks for every advice.
    
asked Sep 7, 2015 by rajesh
0 votes
14 views



Related Hot Questions



Government Jobs Opening


...