黑莓定制Horizo​​ntalFieldManager

发布于 2024-10-11 06:37:26 字数 223 浏览 2 评论 0原文

在 Blackberry 中,我想创建一个扩展 Horizo​​ntalFieldManager 的类,以便我可以在同一行上显示标签和图像,标签在左侧,图像在右侧。
我希望用户能够与 Horizo​​ntalFieldManager 交互,就好像它是单个字段一样。我还希望每个 Horizo​​ntalFieldManager 在添加到 VerticalFieldManager 时都可以聚焦。我还想要 clik 动作事件。

In Blackberry I want to create a class that extends HorizontalFieldManager so that I can display a label and an image on the same line with the label to the left and the image to the right.
I want the user to be able to interact with the HorizontalFieldManager as if it were a single field. I also want each HorizontalFieldManager to be focusable when added to a VeriticalFieldManager. I also want the clcik action events.

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

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

发布评论

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

评论(1

温柔少女心 2024-10-18 06:37:26

听起来您想要开始编写自己的 Field 类,下面是一个帮助您入门的示例:


import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Graphics;

public class SimpleField extends Field {

    private String label;
    private Bitmap image;
    private int fieldWidth;
    private int fieldHeight;
    private boolean hover = false;
    private int focusColor = 0xcccccc;

    public SimpleField(String label, Bitmap image) {
        super(Field.FOCUSABLE);
        this.label = label;
        this.image = image;
        fieldWidth = Display.getWidth();
        fieldHeight = image.getHeight();
    }

    protected void onFocus(int direction) {
        hover = true;
        invalidate();
        super.onFocus(direction);
    }

    protected void onUnfocus() {
        hover = false;
        invalidate();
        super.onUnfocus();
    }

    public int getPreferredWidth() {
        return fieldWidth;
    }

    public int getPreferredHeight() {
        return fieldHeight;
    }

    protected void layout(int width, int height) {
        setExtent(fieldWidth, fieldHeight);
    }

    protected void paint(Graphics graphics) {
        if(hover){
            graphics.setColor(focusColor);
            graphics.fillRect(0, 0, fieldWidth, fieldHeight);
        }
        graphics.drawText(label, 0, (fieldHeight - graphics.getFont().getHeight()) / 2);
        graphics.drawBitmap(graphics.getFont().getAdvance(label), 0, image.getWidth(), image.getHeight(), image, 0, 0);
    }
}

Sounds like you'll be wanting to start writing your own Field classes, here's an example to get you started:


import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Graphics;

public class SimpleField extends Field {

    private String label;
    private Bitmap image;
    private int fieldWidth;
    private int fieldHeight;
    private boolean hover = false;
    private int focusColor = 0xcccccc;

    public SimpleField(String label, Bitmap image) {
        super(Field.FOCUSABLE);
        this.label = label;
        this.image = image;
        fieldWidth = Display.getWidth();
        fieldHeight = image.getHeight();
    }

    protected void onFocus(int direction) {
        hover = true;
        invalidate();
        super.onFocus(direction);
    }

    protected void onUnfocus() {
        hover = false;
        invalidate();
        super.onUnfocus();
    }

    public int getPreferredWidth() {
        return fieldWidth;
    }

    public int getPreferredHeight() {
        return fieldHeight;
    }

    protected void layout(int width, int height) {
        setExtent(fieldWidth, fieldHeight);
    }

    protected void paint(Graphics graphics) {
        if(hover){
            graphics.setColor(focusColor);
            graphics.fillRect(0, 0, fieldWidth, fieldHeight);
        }
        graphics.drawText(label, 0, (fieldHeight - graphics.getFont().getHeight()) / 2);
        graphics.drawBitmap(graphics.getFont().getAdvance(label), 0, image.getWidth(), image.getHeight(), image, 0, 0);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文