Вопрос

I am trying to have the search bar in the actionbar auto open when my search page is launched. I use this to attempt to open the search bar automatically on page open:

@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);

        SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
        searchView.setIconified(false);
        searchView.setOnQueryTextListener(this);
        return true;
    }

The problem is when the page opens, the keyboard pops up but the search bar does not expand so the user can just start typing the search. It looks like this:

enter image description here

Это было полезно?

Решение

  • use searchItem.expandActionView();

  • and in menu file, use showAsAction="ifRoom|collapseActionView"

    If any query, feel free to comment.

Другие советы

You can use setIconifiedByDefault(false) to indicate the default setting

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top