This tutorial will explain you the way to create a transparent popup in blackberry using blackberry SDK. A BlackBerry application requires at least one screen to display information. There are various extensions of the Screen class available in the BlackBerry API set.
FullScreen
A screen that contains a single VerticalFieldManager as its delegate manager.
MainScreen
Extends FullScreen and adds some additional functionality common to many BlackBerry device applications. MainScreen also allows for a title area at the top of the screen followed by a SeparatorField. The main area of the screen is scrollable because this screen contains a VerticalFieldManager as its delegate manager that is inherited from FullScreen. MainScreen also contains an implementation of the makeMenu method to handle menu creation.
PopupScreen
A screen that provides dialog or status screen features.
Dialog
A screen that provides the behaviour of a dialog box that is used to present information to a user and accept input. The alert, ask, inform and doModal methods of the Dialog class will display the Dialog and block (wait) for user input. The show method of the Dialog class does not block, therefore program execution will continue after the Dialog has been displayed.
Status
A screen that provides the features of a dialog but does not accept user input or block. The status screen is designed to display that an action that has taken place. Status screens are set to display for a fixed time or until the user presses the trackwheel, escape key or space key. One of the most commonly used screen classes for a BlackBerry application is MainScreen which provides functionality to easily add a title and menu functions. The following code sample demonstrates use of these methods. In order to create an transparent popup screen similar as shows in the image, you can use the following code.
import com.javatechig.api.ui.AnimatedGIFField; import net.rim.device.api.system.Display; import net.rim.device.api.system.GIFEncodedImage; import net.rim.device.api.ui.Graphics; import net.rim.device.api.ui.Keypad; import net.rim.device.api.ui.Manager; import net.rim.device.api.ui.Screen; import net.rim.device.api.ui.XYRect; import net.rim.device.api.ui.container.VerticalFieldManager; class CustomPopupScreen extends Screen { private final static int _CUSTOM_SIZE = 100; private final static int _ALPHA = 0xEF; // 75% alpha ranges from 0 to 255 private final static int _X = (Display.getWidth() - _CUSTOM_SIZE) >> 1; private final static int _Y = (Display.getHeight() - _CUSTOM_SIZE) >> 1; private static VerticalFieldManager mgr = new VerticalFieldManager(Manager.NO_VERTICAL_SCROLL | Manager.NO_VERTICAL_SCROLLBAR); CustomPopupScreen() { super((Manager) mgr); GIFEncodedImage img = (GIFEncodedImage) GIFEncodedImage.getEncodedImageResource("2.gif"); AnimatedGIFField animation = new AnimatedGIFField(img, 0); add(animation); } protected void sublayout(int width, int height) { setExtent(Display.getWidth(), 50); setPosition(0, Display.getHeight() - 50); layoutDelegate(Display.getWidth(), 50); } protected void paintBackground(Graphics g) { XYRect myExtent = getExtent(); int color = g.getColor(); int alpha = g.getGlobalAlpha(); // making popup transparent g.setGlobalAlpha(_ALPHA); g.setColor(0xE3E3E3); g.fillRect(0, 0, myExtent.width, myExtent.height); g.setColor(color); g.setGlobalAlpha(alpha); } protected boolean keyDown(int keycode, int status) { if (Keypad.key(keycode) == Keypad.KEY_ESCAPE) { close(); return true; } return super.keyDown(keycode, status); } }