Expand and give focus to SearchView automatically

后端 未结 17 2389
囚心锁ツ
囚心锁ツ 2020-12-02 18:21

I\'m developing an application where the user presses the \"Search\" icon in the ActionBar and a SearchView is made visible at the top of the scree

17条回答
  •  庸人自扰
    2020-12-02 18:50

    You can also call to expandActionView() method in order to force it:

    @Override
    public boolean onCreateOptionsMenu( Menu menu )
    {
        super.onCreateOptionsMenu( menu );
    
        MenuItem searchMenuItem = menu.findItem( R.id.mi_search ); // get my MenuItem with placeholder submenu
        searchMenuItem.expandActionView(); // Expand the search menu item in order to show by default the query
    
        return true;
    }
    

    Search item in the Action Bar layout:

    
    

提交回复
热议问题