1

I have this code

toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
    @Override
    public boolean onMenuItemClick(MenuItem item) {
        openSearch();
        return true;
    }
});

into onCreate( ) of my Activity.

OpenSearch function call opens up google now like search view. This only happens when the user clicks on the search action item in the toolbar. In my case I want the search view to open up automatically when the activity starts. How can this menu item click be done programmatically.

I can't call openSearch directly because it needs the menu to be created.

Is there there any callbacks informing that action menus have been created ?

Ahmad Sanie
  • 3,678
  • 2
  • 21
  • 56
Vihaan Verma
  • 12,815
  • 19
  • 97
  • 126

1 Answers1

0

You can try something like this :

 tollbarLayout.getViewTreeObserver().addOnGlobalLayoutListener(
        new ViewTreeObserver.OnGlobalLayoutListener() {

            @Override
            public void onGlobalLayout() {
                     tollbarLayout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                     tollbar.performclick();
                }

            }
        });
Karthik
  • 4,950
  • 6
  • 35
  • 65