黑莓点击字段外

发布于 2024-11-06 20:57:43 字数 743 浏览 4 评论 0原文

我正在为支持触摸的设备(9500,9550,9800,...)实现自定义 ImageButton 我遇到点击(触摸)外部字段在聚焦字段中生成事件的问题。(扩展 FieldBitmapField 时)

我可以通过将焦点移动到空字段来解决它,但是这个不太好。 奇怪的是,这种行为适用于 FieldBitmapField,但不适用于 ButtonField。 看起来确实当 ButtonField 聚焦时,外部点击不会生成按钮事件。

我尝试扩展 ButtonField,但我无法摆脱那个愚蠢的按钮背景。

所以我的问题是; FieldButtonField 之间的行为差​​异是什么导致在 Field 之外生成事件?

这就是我删除按钮背景的方法:

    // cahange button border
    setBorder(BorderFactory
            .createSimpleBorder(new XYEdges(0, 0, 0, 0)));
    setBorder(VISUAL_STATE_ACTIVE, BorderFactory
            .createSimpleBorder(new XYEdges(0, 0, 0, 0)));

I'm implementing a custom ImageButton for touch enabled devices (9500,9550,9800,...)
I have problem that click(touch) outside field generates event in focused field.(when extending Field, BitmapField)

I can solve it by moving focus to empty field, but this is not very nice.
Strange thing is that this behaviour is for Field, BitmapField but not for ButtonField.
It realy seems that when is ButtonField focused, outside clicks don't generates button event.

I tryed extending ButtonField, but I couldn't get rid of that stupid Button Background.

So my question; what is that difference in behavior between Field and ButtonField that causes generating events outside Field?

this is how I removed button background:

    // cahange button border
    setBorder(BorderFactory
            .createSimpleBorder(new XYEdges(0, 0, 0, 0)));
    setBorder(VISUAL_STATE_ACTIVE, BorderFactory
            .createSimpleBorder(new XYEdges(0, 0, 0, 0)));

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

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

发布评论

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

评论(1

╰沐子 2024-11-13 20:57:43

您只需要在 ImageButton 的 touchEvent() 中添加一个检查,

protected boolean touchEvent(TouchEvent message) {
    //make sure the touch is withing the bounds of our Field
    if(message.getX(1) < 0 || message.getX(1) > getWidth() || message.getY(1) < 0 || message.getY(1) > getHeight()) {
        return false;
    }

    //Do your work
}

即使触摸事件实际上不在该字段上,触摸事件也会发送到聚焦的字段,您必须返回 false,以便包含的管理器知道将其发送到下一个将接受它的字段(触摸所在的字段,如果在空白区域则什么也不做)。

编辑:
要删除按钮背景,请覆盖 protected void applyTheme() {}

You just need to add a check in your touchEvent() for the ImageButton

protected boolean touchEvent(TouchEvent message) {
    //make sure the touch is withing the bounds of our Field
    if(message.getX(1) < 0 || message.getX(1) > getWidth() || message.getY(1) < 0 || message.getY(1) > getHeight()) {
        return false;
    }

    //Do your work
}

The touch event is sent to the focused Field even if it isn't actually on the Field, you have to return false so the containing Manager knows to send it to the next Field that will accept it (the Field where the touch is on, or nothing if it is on empty space).

Edit:
To remove the button background, override protected void applyTheme() {}

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