如何在黑莓上突出显示聚焦的自定义按钮字段(ImageButtonField)?

发布于 2025-01-05 10:31:44 字数 1141 浏览 3 评论 0原文

我制作了一个自定义 ButtonField 类,其中有一个图像作为按钮。但是,我希望能够选择该图像并知道它已被选中,可以通过部分突出显示它或在它周围放置一个正方形等方式。我的 UI 中有一个 BitmapField,当我选择它时,它会以蓝色突出显示,但使用 ImageButtonField 的其他图像没有蓝色突出显示。我不希望位图在选择时完全消失。

这是代码:

package mypackage;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Characters;
import net.rim.device.api.ui.component.BitmapField;

    public class ImageButtonField extends BitmapField{

    public ImageButtonField(Bitmap image) {
        super(image);
    }

    public boolean isFocusable() {
        return true;
    }

    protected boolean navigationClick(int status, int time) {
        fieldChangeNotify(0);
        return true;
    }

    protected boolean trackwheelClick(int status, int time) {
        fieldChangeNotify(0);
        return true;
    }

    protected boolean keyChar(char character, int status, int time) {
        if(Characters.ENTER == character || Characters.SPACE == character) {
            fieldChangeNotify(0);
            return true;
        }
        return super.keyChar(character, status, time);
    }
}

任何修改此类以使其正常工作的帮助都会有很大帮助。我没有成功地尝试让这项工作成功!

I made a custom ButtonField class where I have an image as a button. However, I would like to be able to select this image and to know it is selected, either by partially highlighting it or putting a square around it, whatever. I have a BitmapField in my UI that highlights itself in blue when I select it, but my other images that use ImageButtonField, do not have the blue highlight. I do not want the bitmap to disappear completely when selected.

here is the code :

package mypackage;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Characters;
import net.rim.device.api.ui.component.BitmapField;

    public class ImageButtonField extends BitmapField{

    public ImageButtonField(Bitmap image) {
        super(image);
    }

    public boolean isFocusable() {
        return true;
    }

    protected boolean navigationClick(int status, int time) {
        fieldChangeNotify(0);
        return true;
    }

    protected boolean trackwheelClick(int status, int time) {
        fieldChangeNotify(0);
        return true;
    }

    protected boolean keyChar(char character, int status, int time) {
        if(Characters.ENTER == character || Characters.SPACE == character) {
            fieldChangeNotify(0);
            return true;
        }
        return super.keyChar(character, status, time);
    }
}

Any help modifying this class so it works would help immensely. I have had no success trying to make this work!

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

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

发布评论

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

评论(1

森林很绿却致人迷途 2025-01-12 10:31:44

要删除默认样式属性,您可以添加以下方法:

protected void applyTheme(Graphics arg0, boolean arg1) {
}

protected void drawFocus(Graphics graphics, boolean on) {
}

您可以覆盖绘制方法并通过检查焦点状态来绘制任何您想要的内容,例如以下代码将在位图图像上绘制红色透明层。

protected void paint(Graphics graphics) {
    super.paint(graphics);
    if (isFocus()) {
        graphics.setGlobalAlpha(128);
        graphics.setColor(0xFF0000);
        graphics.fillRect(0, 0, getWidth(), getHeight());
    }
}

其实我不太明白你的问题:)。

To remove default styling attributes you can add following methods:

protected void applyTheme(Graphics arg0, boolean arg1) {
}

protected void drawFocus(Graphics graphics, boolean on) {
}

You can override paint method and do paint whatever you want by checking focus status, e.g. following code will paint a red transparent layer over the bitmap image.

protected void paint(Graphics graphics) {
    super.paint(graphics);
    if (isFocus()) {
        graphics.setGlobalAlpha(128);
        graphics.setColor(0xFF0000);
        graphics.fillRect(0, 0, getWidth(), getHeight());
    }
}

Actually I didn't understand your question well :).

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