简体   繁体   中英

BlackBerry image buttons

I want to create six image buttons similar to those on the homescreen, such as settings, downloads, or messages. When I roll to the next button, the previous one must fade, just like the simulator. I am using the 9700 simulator and JDE 5.0.0.

please use this class to make a custom image button and add into a screen:

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.ButtonField;


public class BitmapButtonField extends ButtonField {
    private Bitmap bitmap;
    private Bitmap bitmapHighlight;
    private boolean highlighted = false;

    /**
     * Instantiates a new bitmap button field.
     * 
     * @param bitmap the bitmap to use as a label
     */
    public BitmapButtonField(Bitmap bitmap, Bitmap bitmapHighlight) {
        this(bitmap, bitmapHighlight, ButtonField.CONSUME_CLICK|ButtonField.FIELD_HCENTER|ButtonField.FIELD_VCENTER);
    }

    public BitmapButtonField(Bitmap bitmap, Bitmap bitmapHighlight, long style) {
        super(style);
        this.bitmap = bitmap;
        this.bitmapHighlight = bitmapHighlight;
    }

    /* (non-Javadoc)
     * @see net.rim.device.api.ui.component.ButtonField#layout(int, int)
     */
    protected void layout(int width, int height) {
            setExtent(getPreferredWidth(), getPreferredHeight());
    }

    /* (non-Javadoc)
     * @see net.rim.device.api.ui.component.ButtonField#getPreferredWidth()
     */
    public int getPreferredWidth() {
            return bitmap.getWidth();
    }

    /* (non-Javadoc)
     * @see net.rim.device.api.ui.component.ButtonField#getPreferredHeight()
     */
    public int getPreferredHeight() {
            return bitmap.getHeight();
    }

    /* (non-Javadoc)
     * @see net.rim.device.api.ui.component.ButtonField#paint(net.rim.device.api.ui.Graphics)
     */
    protected void paint(Graphics graphics) {
            super.paint(graphics);
            int width = bitmap.getWidth();
            int height = bitmap.getHeight();
            Bitmap b = bitmap;
            if (highlighted)
                b = bitmapHighlight;
            graphics.drawBitmap(0, 0, width, height, b, 0, 0);
    }

    public void setHighlight(boolean highlight)
    {
        this.highlighted = highlight;           
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM