Controlling toolbar visibility

Floating toolbar

You can define in your application view whether the floating toolbar is shown on view activation. By default, the floating toolbar is hidden.

You can also show or hide the toolbar by changing the toolbar visibility straight from the toolbar itself. In this case, however, remember that closing the application or deactivating the view resets the toolbar visibility state. So after e.g. view deactivation, the toolbar is set visible according to the default setting (defined by the view).

Fixed toolbar

The UI framework always sets the fixed toolbar visible when an application or view is activated. You can change the toolbar visibility straight from the toolbar itself, like in the case of a floating toolbar. However, when hiding the toolbar with the CAknToolbar::SetToolbarVisibility() method, you should note that with that method the toolbar window is completely hidden and some other control should draw to its area to keep the area updated. If this is not applicable, you can use another method: HideItemsAndDrawOnlyBackground() . This will hide the toolbar but draw its background in the toolbar area.

The example below shows how to hide or show the toolbar. You can also use SetToolbarVisibility() with the fixed toolbar if you don't need to draw the toolbar background.

       void CMyAppView::ChangeToolbarVisibility( TBool aHide )
    {
    
    CAknToolbar* toolbar = Toolbar();
    
    if ( !toolbar )
        {
        return;
        }

    // Fixed toolbar        
    if ( toolbar->ToolbarFlags() & KAknToolbarFixed )
        {
        if ( aHide )
            {
            // Hide toolbar but draw background
            toolbar->HideItemsAndDrawOnlyBackground( ETrue );
            }
        else
            {
            // Return situation to normal (toolbar as visible)
            toolbar->HideItemsAndDrawOnlyBackground( EFalse );
            }
        }
        
    // Floating toolbar
    else
        {
        if ( aHide )
            {
            // Hide floating toolbar
            toolbar->SetToolbarVisibility( EFalse );
            }
        else
            {
            // Show floating toolbar
            toolbar->SetToolbarVisibility( ETrue );
            }
        
        }
    }