黑莓图像按钮

发布于 2024-09-28 14:10:57 字数 90 浏览 5 评论 0原文

我想创建六个与主屏幕上类似的图像按钮,例如设置、下载或消息。当我滚动到下一个按钮时,前一个按钮必须消失,就像模拟器一样。我使用的是9700模拟器和JDE 5.0.0。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

江城子 2024-10-05 14:10:57

请使用此类制作自定义图像按钮并添加到屏幕中:

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;           
    }
}

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;           
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文