私はブラックベリーの初心者です。
タブのようなカスタム イメージ ボタン フィールドを使用しています。3 つのイメージ ボタン (タブのような) と 3 つの画面があります。3 つの画面すべてに 3 つのイメージ ボタンがあり、2 つのイメージ ボタンをクリックすると次の画面に移動します。最初の画像ボタン(最初のタブ)のみに焦点を合わせましたが、2番目の画像ボタンに焦点を合わせたいと思っています。
ImageButtonField.java
public class ImageButtonField extends ButtonField {
Bitmap mNormal;
Bitmap mFocused;
Bitmap mActive;
String text;
int mWidth;
int mHeight;
public ImageButtonField(Bitmap normalImage, Bitmap focusedImage,
Bitmap activeImage,String text) {
super(CONSUME_CLICK);
this.text=text;
mNormal = normalImage;
mFocused = focusedImage;
mActive = activeImage;
mWidth = mNormal.getWidth();
mHeight = mNormal.getHeight();
setMargin(0, 0, 0, 0);
setPadding(0, 0, 0, 0);
setBorder(BorderFactory
.createSimpleBorder(new XYEdges(0, 0, 0, 0)));
setBorder(VISUAL_STATE_ACTIVE, BorderFactory
.createSimpleBorder(new XYEdges(0, 0, 0, 0)));
}
protected void paint(Graphics graphics) {
Bitmap bitmap = null;
switch (getVisualState()) {
case VISUAL_STATE_NORMAL:
bitmap = mNormal;
break;
case VISUAL_STATE_FOCUS:
bitmap = mFocused;
break;
case VISUAL_STATE_ACTIVE:
bitmap = mActive;
break;
default:
bitmap = mNormal;
}
graphics.drawBitmap(0, 0, bitmap.getWidth(), bitmap.getHeight(),
bitmap, 0, 0);
if(text!=null)
{
graphics.setColor(Color.WHITE);
graphics.setFont(getFont().derive(Font.BOLD, 28));
// graphics.
graphics.drawText(text,50, 30);
}
}
public int getPreferredWidth() {
return mWidth;
}
public int getPreferredHeight() {
return mHeight;
}
protected void layout(int width, int height) {
setExtent(mWidth, mHeight);
}
}
HomeScreen.java
public final class HomeScreen extends MainScreen implements FieldChangeListener {
private Bitmap homeImageOn;
private Bitmap activateImageOn;
private Bitmap socialImageOn;
private Bitmap homeImageOff;
private Bitmap activateImageOff;
private Bitmap socialImageOff;
private Bitmap logo;
private Bitmap driveNowTextBgImage;
private Bitmap webLink1Image;
private Bitmap webLink2Image;
ImageButtonField homeBitmapImageResource;
ImageButtonField activateBitmapImageResource;
ImageButtonField socialBitmapImageResource;
ImageButtonField logoBitmapResource;
ImageButtonField driveNowBgImageButtonField;
BitmapField webLink1BitmapResorce;
BitmapField webLink2BitmapResorce;
/**
* Creates a new HomeScreen object
*/
public HomeScreen() {
// Set the displayed title of the screen
HorizontalFieldManager tabHorizantalManager = new HorizontalFieldManager();
VerticalFieldManager contentVerticalManager = new VerticalFieldManager();
homeImageOn = Bitmap.getBitmapResource( "home-on.png");
activateImageOff = Bitmap.getBitmapResource( "activate-off.png");
socialImageOff = Bitmap.getBitmapResource( "social-off.png");
homeImageOff = Bitmap.getBitmapResource( "home-off.png");
activateImageOn = Bitmap.getBitmapResource( "activate-on.png");
socialImageOn = Bitmap.getBitmapResource( "social-on.png");
Bitmap bitmap = Bitmap.getBitmapResource("bg.png");
getMainManager().setBackground(
BackgroundFactory.createBitmapBackground(bitmap));
homeBitmapImageResource = new ImageButtonField(homeImageOff,
homeImageOn, homeImageOff, null);
activateBitmapImageResource = new ImageButtonField(activateImageOff,
activateImageOn, activateImageOff, null);
socialBitmapImageResource = new ImageButtonField(socialImageOff,
socialImageOn, socialImageOff, null);
tabHorizantalManager.add(homeBitmapImageResource);
tabHorizantalManager.add(activateBitmapImageResource);
tabHorizantalManager.add(socialBitmapImageResource);
add(tabHorizantalManager);
socialBitmapImageResource.setChangeListener(this);
activateBitmapImageResource.setChangeListener(this);
homeBitmapImageResource.setChangeListener(this);
}
public void fieldChanged(Field field, int context) {
// TODO Auto-generated method stub
if (field.equals(homeBitmapImageResource)) {
UiApplication.getUiApplication().pushScreen(new HomeScreen());
}
if (field.equals(activateBitmapImageResource)) {
ActivateScreen activateScreen = new ActivateScreen();
UiApplication.getUiApplication().pushScreen(activateScreen);
System.out.println("Button pressed: ");
}
if (field.equals(socialBitmapImageResource)) {
UiApplication.getUiApplication().pushScreen(new SocialScreen());
}
}
}