How To implement Custom Menu in our Blackberry Application:-
Step1)
Create a class called BaseMainScreenwhich extends MainScreen.
I ll define the custom menu inside this class.
public class BaseMainScreen extends MainScreen {
Border _menuBorder;
Background _menuBackground,_caretBackground;
Font _menuFont;
protected BaseMainScreen() {
super(MainScreen.NO_VERTICAL_SCROLL | MainScreen.NO_VERTICAL_SCROLLBAR);
XYEdges thickPadding = new XYEdges(10, 10, 10, 10);
_menuBorder = BorderFactory.createBitmapBorder(thickPadding,
Bitmap.getBitmapResource("bb-menu.png"));
/*Bitmap bitmapImage = Bitmap.getBitmapResource("user_pass_bg.png");
_menuBackground=BackgroundFactory.createBitmapBackground(bitmapImage);*/
_menuBackground = BackgroundFactory.createSolidBackground(
Color.DARKGREEN);
_caretBackground = BackgroundFactory.createSolidBackground(
Color.LIMEGREEN);
try {
FontFamily family = FontFamily.forName("Arial");
_menuFont = family.getFont(Font.PLAIN, 30, Ui.UNITS_px);
} catch (final ClassNotFoundException cnfe) {
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
Dialog.alert("FontFamily.forName() threw "
+ cnfe.toString());
}
});
}
}
protected void makeMenu(Menu menu, int context) {
menu.setBorder(_menuBorder);
menu.setBackground(_menuBackground);
menu.setFont(_menuFont);
menu.setCaretBackground(_caretBackground);
super.makeMenu(menu, context);
}
}
Step2)
How to use This BaseMainScreen.
Note:-- create a class called Home and instead of extending MainScren , Simpley extend BaseMainScreen.
public final class Home extends BaseMainScreen implements FieldChangeListener
{
/**
* Creates a new Home object
*/
public Home()
{
setTitle("Amit Blogs");
ButtonField submit=new ButtonField("Submit");
submit.setChangeListener(this);
add(submit);
}
public void fieldChanged(Field arg0, int arg1) {
UiApplication.getUiApplication().pushScreen(new FirstPage());
}
}
Click Here to Download Code
Hi Amit, your code are really good .
ReplyDelete