Showing or hiding the toolbar extension

The toolbar extension is automatically shown when the extension button is pressed.

The extension button is in a latched down state when the extension is open. If the extension button is pressed again, the extension closes and the extension button returns to normal state. This also happens if the user clicks somewhere outside the extension area.

By default, the extension is left open when the user selects an item from the extension. You can change this by defining suitable flags to the button.

The example below shown the definition of a toolbar extension with the button closing the extension when selected.

RESOURCE AVKON_TOOLBAR_EXTENSION r_myapp_toolbar_extension
    {
    items =
        {
        TBAR_CTRL
            {
            type = EAknCtButton;
            id = ECmdExtFirst;
            control = AVKON_BUTTON
                {
                flags = KAknButtonRequestExitOnButtonUpEvent;
                states =
                    {
                    AVKON_BUTTON_STATE
                        {
                        extension = r_myapp_toolbar_ext_first;
                        }  
                    };
                };
            },
…
            }
        };
    }

You can also show or hide the toolbar extension in your application using the methods in the class CAknToolbarExtension .

The example below shows how to hide or show the toolbar extension.

void CMyAppView::ChangeToolbarExtensionVisibility( TBool aHide )
    {
    CAknToolbar* toolbar = Toolbar();
    if ( toolbar )
        {
        CAknToolbarExtension* toolbarExtension = toolbar->ToolbarExtension();
        if ( toolbarExtension )
            {
            if ( aHide )
                {
                toolbarExtension->SetShown( EFalse );
                }
            else
                {
                toolbarExtension->SetShown( ETrue );
                }
            }
        }
    }