Search code examples
androidandroid-toolbar

How to Hide/Show Overflow Icon in ToolBar


how to hide/show overflow icon in custom Toolbar programmatically.

Thanks, Petros


Solution

  • @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    if (!showIcon)
        return false;
    getMenuInflater().inflate(R.menu.main_activity, menu);
    return super.onCreateOptionsMenu(menu);
    }
    

    Now, whenever you want to show the overflow icon just make showIcon variable true otherwise false.