黑莓点击字段外
我正在为支持触摸的设备(9500,9550,9800,...)实现自定义 ImageButton 我遇到点击(触摸)外部字段在聚焦字段中生成事件的问题。(扩展 Field
、BitmapField
时)
我可以通过将焦点移动到空字段来解决它,但是这个不太好。 奇怪的是,这种行为适用于 Field
、BitmapField
,但不适用于 ButtonField
。 看起来确实当 ButtonField
聚焦时,外部点击不会生成按钮事件。
我尝试扩展 ButtonField
,但我无法摆脱那个愚蠢的按钮背景。
所以我的问题是; Field
和 ButtonField
之间的行为差异是什么导致在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您只需要在 ImageButton 的 touchEvent() 中添加一个检查,
即使触摸事件实际上不在该字段上,触摸事件也会发送到聚焦的字段,您必须返回 false,以便包含的管理器知道将其发送到下一个将接受它的字段(触摸所在的字段,如果在空白区域则什么也不做)。
编辑:
要删除按钮背景,请覆盖
protected void applyTheme() {}
You just need to add a check in your touchEvent() for the ImageButton
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() {}