如何在黑莓上突出显示聚焦的自定义按钮字段(ImageButtonField)?
我制作了一个自定义 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要删除默认样式属性,您可以添加以下方法:
您可以覆盖绘制方法并通过检查焦点状态来绘制任何您想要的内容,例如以下代码将在位图图像上绘制红色透明层。
其实我不太明白你的问题:)。
To remove default styling attributes you can add following methods:
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.
Actually I didn't understand your question well :).