Toolbar

Toolbars provide users with a quick and easy way to access frequent actions for an application or screen. Each toolbar consists of a set of icons that appears along the bottom of the screen.

Only smartphones in the BlackBerry® Storm™ Series and BlackBerry® Torch™ 9800 smartphones use toolbars.

Package Toolbar
Supported since BlackBerry® Java® SDK 6.0
Example This screen shows a toolbar.

For more information about toolbars, see the UI Guidelines.

Code sample: Creating a toolbar

import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.image.*;
import net.rim.device.api.ui.toolbar.*;
import net.rim.device.api.util.*;
import net.rim.device.api.system.*;
import net.rim.device.api.command.*;

public class ToolbarDemo extends UiApplication
{
    public static void main(String[] args)
    {

        ToolbarDemo theApp = new ToolbarDemo();       
        theApp.enterEventDispatcher();
    }
    
    public ToolbarDemo()
    {        
        // Push a screen onto the UI stack for rendering.
        pushScreen(new ToolbarDemoScreen());
    }
    
    private final static class ToolbarDemoScreen extends MainScreen
    {
        public ToolbarDemoScreen()
        {              
            if (ToolbarManager.isToolbarSupported()) 
            {
                setTitle("Toolbar Demo");
                
                ToolbarManager manager = new ToolbarManager();
                setToolbar(manager);

                try 
                {
                    Bitmap myBitmap = Bitmap.getBitmapResource("myImg.jpg");
                    Image myImage = ImageFactory.createImage(myBitmap);
                    
                    /*
                     * To create more buttons, Repeat the following lines 
                     * up until manager.add() 
                     */
                    ToolbarButtonField button1 = new ToolbarButtonField(myImage, new StringProvider("butn1"));
                    button1.setCommandContext(new Object()
                    {
                        public String toString()
                        {
                            return "Button1"; 
                        }          
                    });
                    
                    button1.setCommand(new Command(new CommandHandler()
                    {         
                        public void execute(ReadOnlyCommandMetadata metadata, Object context)
                        {
                            Dialog.alert("Executing command for " + context.toString());
                        }           
                    }));
                     
                    manager.add(new ToolbarSpacer(0));
                    manager.add(button1);
                }
                catch (Exception e)
                {
                    System.out.println(e.getMessage());
                }
            } 
            else 
            {
                Dialog.alert("The Toolbar is not supported on this device.");
            }
        }     
    }
}
Next topic: Button
Previous topic: Radio button

Was this information helpful? Send us your comments.