我正在嘗試更改焦點上的自定義按鈕字段的位圖。我有2張圖片,一張是灰色的,另一張是紅色的,我希望在按鈕被聚焦時交換它們。如何更改焦點上的自定義buttonfield位圖? (Blackberry)
此代碼正在將按鈕抽搐的時間從灰色變爲紅色的幾分之一秒。聚焦時,它被選中,併產生不需要的事件。改變後,它會回到原來的顏色,模擬器凍結。
任何人都可以幫助我們找到這個代碼有什麼問題嗎?
我定製ButtonField字段類:
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Characters;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.BitmapField;
public class ImageNavbarButtonField extends BitmapField{
private Bitmap image;
private boolean isFocused;
public ImageNavbarButtonField(Bitmap image) {
super(image);
this.image = 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 void drawFocus(Graphics graphics, boolean on){}
public void onFocus(){
setBitmap(ImageResizer.generateHitBitmap(image));
invalidate();
}
public void onUnfocus(){
//super.onUnfocus();
setBitmap(image);
invalidate();
}
protected void paint(Graphics graphics) {
super.paint(graphics);
}
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);
}
}