黑莓4.5 - 如何点击.jpg图像?
问题描述:
我在BitmapField中显示.jpg图像&将其添加到VerticalFieldManager中。它正在显示,但我不能点击它。黑莓4.5 - 如何点击.jpg图像?
我在做它像..
Bitmap bitmap = Bitmap.getBitmapResource("image.jpg");
BitmapField bitmapField = new BitmapField(bitmap , BitmapField.FOCUSABLE)
{
protected boolean navigationClick(int status, int time)
{
//handle click event
return true;
}
};
VerticalFieldManager vfm = new VerticalFieldManager();
vfm.add(bitmapField);
add(vfm_stamp);
但是,如果我把一个PNG图片像
Bitmap bitmap = Bitmap.getBitmapResource("image.png");
那么它是可以点击的。为什么这样?
黑莓4.5支持.jpg图片格式。它显示一个.jpg图片,为什么它不可点击?我想让它可点击。
怎么办?
答
您可以覆盖方法onFocus()
并在选中时更改其行为。
你也可以创建一个扩展net.rim.device.api.ui.Field
一个BitmapButton您需要setChangeListener()
为您bitmapField
+0
如果JPG不透明或者没有透明边框,那么我不会看到焦点。 因此,我使用方法setSpace(int,int)在位图周围添加了一些边距。现在它的工作..谢谢.. – Shreyas 2010-01-23 04:50:40
答
您可以同时能延长ButtonField:
package org.ci.blackberry.ui;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.ButtonField;
public class BitmapButtonField45 extends ButtonField {
private static final int STATE_NORMAL = 0;
private static final int STATE_FOCUS = 1;
private static final int STATE_ACTIVE = 2;
Bitmap mNormal;
Bitmap mFocused;
Bitmap mActive;
int mWidth;
int mHeight;
private int mState = STATE_NORMAL;
public BitmapButtonField45(Bitmap normal, Bitmap focused,
Bitmap active) {
super(CONSUME_CLICK);
mNormal = normal;
mFocused = focused;
mActive = active;
mWidth = mNormal.getWidth();
mHeight = mNormal.getHeight();
}
public BitmapButtonField45(Bitmap normal, Bitmap focused) {
this(normal, focused, focused);
}
protected void paint(Graphics graphics) {
Bitmap bitmap = null;
switch (getState()) {
case STATE_NORMAL:
bitmap = mNormal;
break;
case STATE_FOCUS:
bitmap = mFocused;
break;
case STATE_ACTIVE:
bitmap = mActive;
break;
default:
bitmap = mNormal;
}
graphics.drawBitmap(0, 0, bitmap.getWidth(), bitmap.getHeight(),
bitmap, 0, 0);
}
public int getState() {
return mState;
}
protected void applyTheme()
{}
protected void onFocus(int direction) {
mState = STATE_FOCUS;
super.onFocus(direction);
}
protected void onUnfocus() {
mState = STATE_NORMAL;
super.onUnfocus();
}
protected boolean navigationClick(int status, int time) {
mState = STATE_ACTIVE;
return super.navigationClick(status, time);
}
protected boolean navigationUnclick(int status, int time) {
mState = STATE_NORMAL;
return super.navigationUnclick(status, time);
}
public int getPreferredWidth() {
return mWidth;
}
public int getPreferredHeight() {
return mHeight;
}
protected void layout(int width, int height) {
setExtent(getPreferredWidth(), getPreferredHeight());
}
}
使用示例:PuzzleApp.java
是一个.jpg图片在Blackberry 4.5中可点击吗?如果是,那么该怎么做? – Shreyas 2010-01-22 09:55:47
我的方法也被点击。只有当指针在其上移动时,.jpg图像不显示焦点(蓝色背景)。 如何显示焦点? – Shreyas 2010-01-22 13:40:04
重写受保护的void drawFocus(Graphics graphics,boolean on){}就像您使用navigationClick所做的那样 – Alex 2010-03-17 14:53:51