问题描述
我实现自定义的ImageButton对触摸功能的设备(9500,9550,9800,...)
我有一个点击(触摸)外场聚焦磁场产生事件的问题。(扩展时字段
, BitmapField
)
我可以通过移动焦点到空字段解决它,但是这是不是很漂亮。
奇怪的是,这种行为是对字段
, BitmapField
而不是 ButtonField字段
。
这真的好像是当 ButtonField字段
重点,外面点击不生成按钮事件。
我tryed延长 ButtonField字段
,但我无法摆脱那个愚蠢的按钮背景的。
所以我的问题;是什么字段之间的行为差异
和 ButtonField字段
引起外界生成事件字段
?
这是我如何删除按钮的背景:
// cahange按钮边框
setBorder(BorderFactory
.createSimpleBorder(新XYEdges(0,0,0,0)));
setBorder(VISUAL_STATE_ACTIVE,BorderFactory
.createSimpleBorder(新XYEdges(0,0,0,0)));
您只需要在您的TouchEvent(添加一个检查)的ImageButton的
保护布尔的TouchEvent(的TouchEvent消息){
//确保触摸withing我们的现场的边界
如果(message.getX(1)℃,|| message.getX(1)>的getWidth()|| message.getY(1)℃,|| message.getY(1)>的getHeight()){
返回false;
} //做你的工作
}
触摸事件被发送到集中域,即使它实际上不是在球场上,你必须返回false所以含有Manager知道将其发送到下一个字段将接受它(字段中的触摸是上,或没有,如果它是在空的空间)。
编辑:
要删除按钮的背景下,覆盖保护无效applyTheme(){}
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)));
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() {}
这篇关于场外黑莓手机点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!